Learn Cocoa on the Mac - David Mark, Jeff LaMarche, Jack Nutting

Learn Cocoa on the Mac (eBook)

eBook Download: PDF
2010 | 1st ed.
400 Seiten
Apress (Verlag)
978-1-4302-1860-9 (ISBN)
Systemvoraussetzungen
35,30 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

The Cocoa frameworks are some of the most powerful frameworks for creating native desktop applications available on any platform today, and Apple gives them away, along with the Xcode development environment, for free! However, for a first-time Mac developer, just firing up Xcode and starting to browse the documentation can be a daunting task. The Objective-C class reference documentation alone would fill thousands of printed pages, not to mention all the other tutorials and guides included with Xcode. Where do you start? Which classes are you going to need to use? How do you use Xcode and the rest of the tools?

This book answers these questions and more, helping you find your way through the jungle of classes, tools, and new concepts so that you can get started on the next great Mac OS X application today. Jack Nutting is your guide through this forest; he's lived here for years, and he'll show you which boulder to push, which vine to chop, and which stream to float across in order to make it through. You will learn not only how to use the components of this rich framework, but also which of them fit together, and why.

Jack Nutting's approach, combining pragmatic problem-solving with a deep respect for the underlying design philosophies contained within Cocoa, stems from years of experience using these frameworks. He'll show you which parts of your application require you to jump in and code a solution, and which parts are best served by letting Cocoa take you where it wants you to go. The path over what looks like a mountain of components and APIs has never been more thoroughly prepared for your travels. With Jack's guidance, the steep learning curve becomes a pleasurable adventure. There is still much work for the uninitiated, but by the time you're done, you will be well on your way to becoming a Cocoa master.



Dave Mark is a longtime Mac developer and author who has written a number of books on Mac and iOS development, including Beginning iPhone 4 Development (Apress, 2010), More iPhone 3 Development (Apress, 2010), Learn C on the Mac (Apress, 2008), The Macintosh Programming Primer series (Addison-Wesley, 1992), and Ultimate Mac Programming (Wiley, 1995). Dave loves the water and spends as much time as possible on it, in it, or near it. He lives with his wife and three children in Virginia.
The Cocoa frameworks are some of the most powerful frameworks for creating native desktop applications available on any platform today, and Apple gives them away, along with the Xcode development environment, for free! However, for a first-time Mac developer, just firing up Xcode and starting to browse the documentation can be a daunting task. The Objective-C class reference documentation alone would fill thousands of printed pages, not to mention all the other tutorials and guides included with Xcode. Where do you start? Which classes are you going to need to use? How do you use Xcode and the rest of the tools?This book answers these questions and more, helping you find your way through the jungle of classes, tools, and new concepts so that you can get started on the next great Mac OS X application today. Jack Nutting is your guide through this forest; he's lived here for years, and he'll show you which boulder to push, which vine to chop, and which stream to float across in order to make it through. You will learn not only how to use the components of this rich framework, but also which of them fit together, and why.Jack Nutting's approach, combining pragmatic problem-solving with a deep respect for the underlying design philosophies contained within Cocoa, stems from years of experience using these frameworks. He'll show you which parts of your application require you to jump in and code a solution, and which parts are best served by letting Cocoa take you where it wants you to go. The path over what looks like a mountain of components and APIs has never been more thoroughly prepared for your travels. With Jack's guidance, the steep learning curve becomes a pleasurable adventure. There is still much work for the uninitiated, but by the time you're done, you will be well on your way to becoming a Cocoa master.

Dave Mark is a longtime Mac developer and author who has written a number of books on Mac and iOS development, including Beginning iPhone 4 Development (Apress, 2010), More iPhone 3 Development (Apress, 2010), Learn C on the Mac (Apress, 2008), The Macintosh Programming Primer series (Addison-Wesley, 1992), and Ultimate Mac Programming (Wiley, 1995). Dave loves the water and spends as much time as possible on it, in it, or near it. He lives with his wife and three children in Virginia.

Title Page 1
Copyright Page 2
Contents at a Glance 3
Table of Contents 4
Foreword 10
About the Authors 11
About the Technical Reviewer 12
Acknowledgments 13
Preface 14
Chapter 1 Must Love Cocoa 15
Get a Mac and Download the Tools 16
Download the Source Code 17
Getting Help 17
What You Need to Know Before You Begin 17
Are You Ready? 18
Chapter 2 Hello, World 19
Building “Hello, World” 19
Exploring the Nib File 23
The Library 24
Dragging Out a Label 26
Using the Blue Guidelines 27
The Inspector Window 28
The Attributes Inspector 29
Change the Label’s Color and Font 31
Using the Menu Editor 33
Creating Your Application Icon 35
Adding Your Icon to Your Project 36
Property Lists 39
Running Your Application 39
Sharing Your Creation With the World 40
Goodbye, Hello World 42
Chapter 3 Lights, Camera… Actions! (and Outlets, Too) 43
This Chapter’s Application 44
Frameworks, Frameworks Everywhere 44
The Foundation Framework 45
The AppKit Framework 45
The Cocoa Way: Model-View-Controller 46
Outlets, Actions, and Controllers 47
Declaring Outlets 47
Declaring Actions 48
Outlets and Actions in Action 49
Enabling Garbage Collection 49
Creating Our Controller Class 51
Declaring an Action and Outlet 52
Back to Interface Builder 53
Proxy Objects 54
Creating the Controller Instance 55
Setting Up the Window 56
Designing the Window’s Interface 60
Connecting the Outlet 62
Connecting the Buttons to Our Action 63
Implementing the Action Method 64
The Application Delegate 65
Configuring the Application to Quit on Window Close 66
Using the Documentation Browser 67
Bring It on Home 68
Chapter 4 GUI Components 69
Creating the VillainTracker Application 71
Creating the VillainTrackerAppDelegate Class 72
Planning for the GUI 74
Building Your Interface 76
Bringing Out Your Text Fields 76
Letting them Pick Dates 78
Creating the Combo Box 79
Indicating a Rating with a Level Indicator 80
Adding Radio Buttons in a Matrix 81
Adding an Image View 84
Adding Checkboxes in a Matrix 85
Configuring a Popup Button 86
Inserting a Text View 87
Making Logical Groupings 87
Resizing 90
Time for the Controller 92
Making All the Connections 92
Getting Started with Coding 94
Standardizing Key Names 94
Creating the Default Villain 95
Paying Attention to Detail 96
Setting Simple Values 97
Values in Complex Controls 98
Responding to Input 101
In Conclusion 104
Chapter 5 Using Table Views 105
Preparing AppController for Multiple Villains 105
Making Way for the Table View 107
Tweaking the Autosizing Characteristics 110
Making Some New Connections 112
Making Way for the Table View: Code Edition 113
The Table View Needs Your Help 114
Adding and Deleting Villains 116
In Conclusion 118
Chapter 6 Cocoa Bindings 119
Binding to Simple Controls 120
Create the DungeonThing Project 120
Create a Preferences Window 121
Add a Tab View 122
Character Generation Preferences 122
Monster Generation Preferences 124
Dungeon Generation Preferences 124
Binding to NSUserDefaultsController 125
Bindings for Character Generation 125
Bindings for Monster Generation 127
Bindings for Dungeon Generation 127
Create the Main Window 128
Set Up the DungeonThingAppDelegate 130
Define Your Constants 130
Specify Default Preferences Values 131
Create the Action Methods 132
Binding to a Table View 134
Make the Code Bindings-Ready 135
Show History in Tables 138
Dealing With Inconsistencies in Nib Files 138
Configuring the Table Views and Text Views 138
Create and Configure an Array Controller 140
Bind Table Display via the Array Controller 142
Bind a Text Field via the Array Controller’s Selection 142
Making Sure it Works 143
Rinse, Repeat, Rinse, Repeat 143
Okay, But How Did That Work? 143
Key-Value Coding 143
Key-Value Observing 145
Cocoa Bindings: How It Works 145
In Conclusion 146
Chapter 7 Core Data Basics 147
What You’ve Been Missing 147
Creating MythBase 149
Defining the Model 150
Using Xcode’s Model Editor 151
Creating an Entity 152
Creating Attributes 153
Attributes for Unsupported Types 155
The Automatic GUI 156
Refining the GUI 159
Exploring the Template Code 164
The App Delegate Interface 164
The App Delegate Implementation 166
The applicationSupportDirectory Method 166
The managedObjectModel Accessor Method 167
The persistentStoreCoordinator Accessor Method 168
The managedObjectContext Accessor Method 170
An NSWindow Delegate Method 170
The saveAction: Action Method 171
An NSApplication Delegate Method 171
The Obligatory Dealloc Method 173
Adding Business Logic 173
Validating Single Attributes 174
Validating Multiple Attributes 174
Creating a Custom Attribute 177
In Conclusion 178
Chapter 8 Core Data Relationships 179
Modeling New Entities and Relationships 180
Model Versioning and Migrations 181
Preparing for Multiple Model Versions 181
Adding New Entities 181
Add Relationships 182
Creating a Simple Migration 184
Time to Run 186
Updating the GUI 187
Create the Band Window 187
Giving Useful Names to Array Controllers 188
Putting People in Bands 189
Showing the Bands’ Members 191
Create a Venue Window 193
Adding a Gig List to the Band Window 193
Wrapping Up Relationships 195
Chapter 9 Search and Retrieve Core Data with Criteria 197
Creating QuoteMonger 197
Create the Project and Its Data Model 198
The Data Entry Window 199
A Two-Part Autogenerated Window 199
Smoothing Out the Rough Spots 200
Enter Some Initial Quotes 201
Creating the Quote Finder Window 202
Limiting Results with NSPredicate 203
Creating Predicates 203
Specifying an NSAppController’s Predicate in Interface Builder 205
User-Defined Predicates 205
Adding a Predicate to the App Delegate 206
Add a Predicate Editor to the Search Window 207
Configuring the Predicate Editor 207
Saving a Predicate 209
In Conclusion 210
Chapter 10 Windows and Menus and Sheets 211
NSWindow and NSPanel 211
Handling Input 213
To Use a Panel, or Not to Use a Panel 213
Window Attributes 214
Standard System Panels 215
The Color Panel 216
The Font Panel 218
A Controller With a Nib of Its Own 219
Loading a Nib With NSWindowController 220
Subclassing NSWindowController 221
Modal Windows 223
The NSAlert Functions 223
Open Panels and Save Panels 224
System Menus 225
Standard Application Menu Items 226
Your Own Menus 226
Enabling/Disabling With Bindings 227
Enabling/Disabling With First Responder 229
Sheets 232
Wrap-up 234
Chapter 11 Document-Based Applications 235
Creating the ColorMix Application 236
Examining the Default Nib Files 237
Defining the Model 237
Setting Two Colors 238
The Simplest of GUIs 239
Creating a Default ColorSet 240
Settling on a File Format 241
Adding Color 241
The ColorBlendView Class 242
Adding Blended Colors to the GUI 244
Adding Some Background Bling 248
About Undo and Redo 250
The Undo Stack 250
In Conclusion 251
Chapter 12 Exceptions, Signals, Errors, and Debugging 252
Exception Handling 252
Catching Exceptions 253
The Limited Role of Exceptions in Cocoa 254
Create a Test-bed 254
NSInvalidArgumentException 259
NSRangeException 262
And the Rest 263
Worse than Exceptions: Death by Signal 264
NSError 266
Domains and Codes 266
Realizing You Have an Error 267
Presenting an Error 271
In Conclusion 271
Chapter 13 Drawing in Cocoa 272
Fundamentals 272
The View Coordinate System 273
Frame Rectangle vs. Bounds Rectangle 273
Rects, Points, and Sizes 274
Path Basics 274
Creating an NSView Subclass 275
Some C Structures 275
The Basic Drawing Method, drawRect 276
Graphics States 276
Path Helpers 276
Colors and the Graphics Context 277
Beyond Color 278
Manual Path Construction 279
Pushing Boundaries 279
LOLmaker 282
First Steps to LOL 282
LOLView 284
Drawing a Bitmap 285
Let It Scroll 286
Drawing Text 288
Printing Basics 290
Wrapping Up 291
Chapter 14 Advanced Drawing Topics 292
Editing a Curve 292
Preparations 293
Bezier Plumbing 295
Drawing a Curve 296
Watching the Mouse 298
A Little Polish 300
Core Animation: A Primer 301
Core Animation Basics 302
Implicit Animations 302
Explicit Animations 303
Grouping Animations 308
What Have We Done? 315
Chapter 15 Working with Files 316
Implicit File Access 316
High-level File Operations 317
What About That File: The Code 318
What About That File: The GUI 323
Filing It All Away 327
Chapter 16 Concurrency 328
SlowWorker 329
Threading Basics 331
Units of Work 332
Operation Queues 333
Vitalizing SlowWorker 333
Extending NSObject 336
Demanding the Main Thread 337
GCD: Low-Level Queuing 342
Becoming a Blockhead 343
Improving SlowWorker a Second Time 344
Don’t Forget That Main Thread 345
Concurrent Blocks 345
Another Option: NSBlockOperation 346
A Little Concurrency Goes a Long Way 347
Chapter 17 Future Paths 348
More Cocoa-isms 348
Notifications 349
Blocks 350
Enumeration 350
Observing Notifications Using Blocks 352
Filtering 352
Cocoa in a Foreign Language 352
PyObjC 353
MacRuby 354
Nu 355
JavaScript 355
F-Script 356
Ported Cocoa 356
Cocoa Touch 357
GNUstep and Cocotron 357
Cappuccino/Objective-J 358
Here at the End of All Things 359
Index 360

Erscheint lt. Verlag 25.6.2010
Zusatzinfo 400 p.
Verlagsort Berkeley
Sprache englisch
Themenwelt Informatik Betriebssysteme / Server Macintosh / Mac OS X
Informatik Programmiersprachen / -werkzeuge Mac / Cocoa Programmierung
Mathematik / Informatik Informatik Theorie / Studium
Schlagworte App • CoCoA • Cocoa Touch • Debugging • iPhone • Objective-C • Xcode
ISBN-10 1-4302-1860-6 / 1430218606
ISBN-13 978-1-4302-1860-9 / 9781430218609
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 6,6 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich