وبلاگ بلیان

Cocoa Programming: A Quick-Start Guide for Developers (Pragmatic Programmers)

معرفی کتاب «Cocoa Programming: A Quick-Start Guide for Developers (Pragmatic Programmers)» نوشتهٔ Daniel H. Steinberg، منتشرشده توسط نشر The Pragmatic Bookshelf در سال 2010. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است. «Cocoa Programming: A Quick-Start Guide for Developers (Pragmatic Programmers)» در دستهٔ بدون دسته‌بندی قرار دارد.

As a web developer, I was a little worried about picking up a compiled language to add to my toolbelt, since the paradigm is so much different from the normal scripting and object oriented programming I'm used to, but so far "Cocoa Programming: A quick start guide for developers" has been an excellent introduction. I am a big fan of PragProg books in general and this book is no exception. Written in a clear and conversation tone, this book is helping me get up to speed with the Cocoa framework from the very practical point-of-view of the XCode/InterfaceBuilder workflow and introducing Objective-C concepts in a way that is illuminating and not intimidating. Its not a deep resource manual, there are other books that do that, but if you're looking to see what is like to build OS X applications, this is a great first step. Contents......Page 7 Moving In......Page 15 Learning the Language......Page 18 Installing the Tools......Page 19 Exploring the Frameworks......Page 20 In This Book......Page 21 Using What's There......Page 24 Creating Your Project in Xcode......Page 25 Creating the Appearance with Interface Builder......Page 26 Testing the Interface with the Cocoa Simulator......Page 31 Finishing the Interface......Page 33 Wiring Up the Components......Page 35 Fixing the Build......Page 39 Sharing Your Browser......Page 41 Exercise: Rinse and Repeat......Page 42 The Nib File......Page 43 Sending Messages Without Arguments......Page 48 Reading the Docs......Page 50 Methods with Arguments......Page 53 Dynamic Binding......Page 56 Problems Sending Messages......Page 57 Links Back to Yourself......Page 58 Exercise: Multiple Connections......Page 59 Creating ``Hello, World!''......Page 62 Logging Output to the Console......Page 63 Using an Existing Class......Page 66 Refactoring Code......Page 69 Creating a New Class......Page 72 Creating and Using a Class Method......Page 75 Creating a New Object......Page 76 Further Refactoring......Page 78 Initializing Your Objects......Page 79 Logging Objects......Page 82 Exercise: Other Initializations......Page 83 Solution: Other Initializations......Page 84 Instance Variables and Properties......Page 86 Pointers......Page 87 Working with Nonobject Types......Page 88 Getters and Setters......Page 89 Converting the Accessors to Properties......Page 92 Dot Notation......Page 93 Property Attributes......Page 96 Exercise: Adding Properties......Page 98 Solution: Adding Properties......Page 99 Removing Instance Variables......Page 100 Memory......Page 102 Reference Counting......Page 103 Finding Leaks with the Clang Static Analyzer......Page 104 Fixing the Memory Leak on Mac OS X......Page 106 Properties and Garbage Collection......Page 107 Creating a Flashlight......Page 109 Finding Leaks in Instruments......Page 111 Fixing the Memory Leak on the iPhone......Page 112 Using Zombies......Page 113 Cleaning Up in dealloc......Page 115 Retain and Release in a Setter......Page 116 The Autorelease Pool......Page 117 Using Convenience Constructors......Page 120 Exercise: Creating and Using a Convenience Constructor......Page 121 Solution: Creating and Using a Convenience Constructor......Page 122 Outlets and Actions......Page 124 Using an Outlet......Page 125 Exercise: Creating and Using an Outlet......Page 128 Solution: Creating and Using an Outlet......Page 129 Declaring an Action......Page 130 Connecting and Implementing the Action......Page 133 Solution: Hiding the Button......Page 135 Solution: Toggling the Interface......Page 136 Introducing Another Outlet......Page 137 Creating Selectors from Strings......Page 139 How We've Created Objects......Page 141 Creating Our Controller Class......Page 143 Creating an Instance of Our Controller in IB......Page 144 Declaring an Outlet and an Action......Page 146 Forward Declaration......Page 149 Exercise: Finishing the Controller......Page 150 Solution: Finishing the Controller......Page 151 Awake from Nib......Page 152 Disabling and Enabling the Buttons......Page 153 Still Needs Work......Page 156 Understanding Delegates......Page 158 Turning the Background Red......Page 162 Application Delegate......Page 165 Delegates for Your Web View......Page 166 Setting the Window Title......Page 167 Exercise: Updating the URL and Setting Buttons......Page 169 Cleaning Up......Page 170 Solution: Adding a Progress Indicator......Page 173 Creating the iPhone Project......Page 175 Creating the Look of Our Browser......Page 177 The WebView's Limitations......Page 178 Loading a Web Page at Launch......Page 179 Tweaking the Text Field in IB......Page 181 Using the Text Field Delegate......Page 183 Using a Third Delegate to Implement the Buttons......Page 184 Exercise: Adding an Activity Indicator......Page 185 Solution: Adding an Activity Indicator......Page 186 Organizing with Pragma Marks......Page 188 Posting and Listening for Notifications......Page 191 Solution: Creating a Model......Page 192 Registering for Notifications......Page 194 Responding to Workspace Activity......Page 195 Holding on to the Controller......Page 197 Solution: Registering for Notifications......Page 198 Posting Notifications......Page 199 Solution: Receiving the Custom Notifications......Page 201 Creating Protocols for Delegation......Page 203 Solution: Creating and Setting the Delegate......Page 204 Creating and Using a Protocol......Page 205 Requiring Methods......Page 207 Exercise: Calling the Delegate Methods......Page 208 Solution: Cleaning Up......Page 209 Looking at the User Info......Page 213 Reading from a Dictionary......Page 214 Solution: Displaying the Name......Page 215 Reducing Redundancy......Page 216 Adding and Removing Entries with a Mutable Dictionary......Page 218 Exercise: Adding an Icon......Page 221 Solution: Adding an Icon......Page 223 Methods, Objects, and Nibs......Page 227 Splitting Nibs......Page 229 Preparing to Split Out the View......Page 231 Creating the View Nib......Page 232 Integrating a Nib File......Page 233 The File's Owner......Page 235 Exercise: Loading the View......Page 236 Creating the Window Nib......Page 237 Loading the Window Nib......Page 239 Exercise: Connecting the View and the Model......Page 240 Solution: Connecting the View and the Model......Page 241 Creating a Custom View......Page 243 Drawing Shapes into a Custom View......Page 245 Solution: Changing the Stroke Color......Page 248 Drawing Images......Page 250 Drawing Text......Page 252 Tables and Data Sources......Page 256 Exercise: Implementing a Basic Data Source......Page 259 Solution: Implementing a Basic Data Source......Page 260 Exercise: Introducing a Data Source......Page 261 Solution: Introducing a Data Source......Page 262 Filling Cells Based on Table Column Titles......Page 263 Table Column Identifiers as Keys......Page 265 Exercise: Adding and Removing Rows......Page 266 Solution: Adding and Removing Rows......Page 267 Manually Removing Rows......Page 268 Saving in Your Running Application......Page 270 Where to Put Application Support......Page 273 Saving to a Plist......Page 274 Reading a Plist......Page 275 Saving an Archive to Disk......Page 276 Setting the Factory Defaults......Page 278 Preparing to Set User Defaults......Page 280 The Preference Window Nib......Page 281 Enabling the Preferences Window......Page 283 Working with Radio Buttons......Page 285 Adding Preferences for View at Launch......Page 287 Solution: Launching with the Right View......Page 288 Eliminating Magic Numbers......Page 290 Customizing the Menu Bar......Page 292 Moving the Main Window......Page 293 Solution: Switching Views (Mostly)......Page 294 Lazy Initialization......Page 296 Key Value Coding......Page 298 Treating Objects Like Dictionaries......Page 299 Getting Variables Using KVC......Page 301 Undefined Keys......Page 303 Solution: Setting Variables Using KVC......Page 304 KVC and Dictionaries......Page 305 Keypaths for Navigating a Class Hierarchy......Page 306 Solution: Filling Tables Using KVC......Page 309 Arrays and KVC......Page 311 Codeless Connections......Page 314 A Target-Action Counter......Page 316 Introducing an Observer......Page 318 Registering an Observer......Page 320 Making Changes Observable......Page 321 Observing the Changes......Page 323 Solution: Adding a Second Observer......Page 324 The Ugly Way to Observe More Than One Attribute......Page 325 Selecting Methods Using KVC......Page 328 Implementing an Observer Object......Page 329 Updating Dependent Variables......Page 331 Cocoa Bindings......Page 334 Creating and Connecting the NSObjectController......Page 335 Binding More Objects......Page 338 Number Formatters......Page 339 Exercise: Connecting Two Counters with Bindings......Page 341 Solution: Connecting Two Counters with Bindings......Page 342 The Model for Our Bookshelf Example......Page 344 Creating the View for the Bookshelf......Page 345 Binding with the NSArrayController......Page 346 The Big Finish......Page 349 Core Data......Page 350 Entities and Attributes......Page 351 Using the Core Data Widget......Page 352 The Managed Object Context......Page 354 The Persistence Layer......Page 356 Introducing Relationships......Page 358 Choosing a Relationship's Delete Rule......Page 360 Updating the View......Page 361 Managing Dependencies......Page 362 Sorting......Page 363 Filtering Items......Page 365 Coding the Sort Descriptor......Page 366 Overcoming Limitations......Page 368 Creating a Category......Page 369 Category Cautions......Page 371 Private Methods in Class Extensions......Page 372 Solution: Extending Properties with Class Extensions......Page 375 Categories and Core Data......Page 376 Generated Classes in Core Data......Page 378 Accessing Properties......Page 379 Regenerating Class Files from Entities......Page 380 Blocks......Page 383 The Need for Blocks in Wrappers......Page 384 Declaring a Block......Page 385 Using Blocks in Wrappers......Page 386 Capturing Values......Page 387 Blocks and Collections......Page 389 Declaring, Defining, and Using Blocks......Page 390 Using __block......Page 392 Cleaning Up with typedef......Page 393 Exercise: Using Blocks in Callbacks......Page 394 Solution: Using Blocks in Callbacks......Page 396 Making the Beach Ball Spin......Page 398 Invocation Operations......Page 400 Block Operations......Page 402 Interacting with the Queue and Operations......Page 403 Custom NSOperations......Page 406 From Operation Queues to Dispatch Queues......Page 408 When to Use Dispatch Queues......Page 412 Quick Queue Overview......Page 414 Drawing Our Fractal......Page 415 Working Without Dispatch Queues......Page 416 The Main Queue......Page 418 Global Concurrent Queues......Page 419 Synchronizing on the Main Queue......Page 420 Private Dispatch Queues......Page 421 Synchronous Tasks......Page 422 But What About.........Page 426 What's Next......Page 427 Acknowledgments......Page 428 Dedication......Page 429 Bibliography......Page 431 A......Page 434 C......Page 435 D......Page 437 E......Page 438 I......Page 439 L......Page 440 M......Page 441 N......Page 442 O......Page 443 P......Page 444 R......Page 445 S......Page 446 V......Page 447 Y......Page 448 Z......Page 449 Contents 7 Introduction 15 Moving In 15 Learning the Language 18 Installing the Tools 19 Exploring the Frameworks 20 In This Book 21 Using What's There 24 Creating Your Project in Xcode 25 Creating the Appearance with Interface Builder 26 Testing the Interface with the Cocoa Simulator 31 Finishing the Interface 33 Wiring Up the Components 35 Fixing the Build 39 Sharing Your Browser 41 Exercise: Rinse and Repeat 42 The Nib File 43 Methods and Parameters 48 Sending Messages Without Arguments 48 Reading the Docs 50 Methods with Arguments 53 Dynamic Binding 56 Problems Sending Messages 57 Links Back to Yourself 58 Exercise: Multiple Connections 59 Classes and Objects 62 Creating ``Hello, World!'' 62 Logging Output to the Console 63 Using an Existing Class 66 Refactoring Code 69 Creating a New Class 72 Creating and Using a Class Method 75 Creating a New Object 76 Further Refactoring 78 Initializing Your Objects 79 Logging Objects 82 Exercise: Other Initializations 83 Solution: Other Initializations 84 Instance Variables and Properties 86 Pointers 87 Working with Nonobject Types 88 Getters and Setters 89 Converting the Accessors to Properties 92 Dot Notation 93 Property Attributes 96 Exercise: Adding Properties 98 Solution: Adding Properties 99 Removing Instance Variables 100 Memory 102 Reference Counting 103 Finding Leaks with the Clang Static Analyzer 104 Fixing the Memory Leak on Mac OS X 106 Properties and Garbage Collection 107 Creating a Flashlight 109 Finding Leaks in Instruments 111 Fixing the Memory Leak on the iPhone 112 Using Zombies 113 Cleaning Up in dealloc 115 Retain and Release in a Setter 116 The Autorelease Pool 117 Using Convenience Constructors 120 Exercise: Creating and Using a Convenience Constructor 121 Solution: Creating and Using a Convenience Constructor 122 Outlets and Actions 124 The Big Picture 125 Using an Outlet 125 Exercise: Creating and Using an Outlet 128 Solution: Creating and Using an Outlet 129 Declaring an Action 130 Connecting and Implementing the Action 133 Exercise: Hiding the Button 135 Solution: Hiding the Button 135 Exercise: Toggling the Interface 136 Solution: Toggling the Interface 136 Introducing Another Outlet 137 Creating Selectors from Strings 139 Creating a Controller 141 How We've Created Objects 141 Creating Our Controller Class 143 Creating an Instance of Our Controller in IB 144 Declaring an Outlet and an Action 146 Forward Declaration 149 Wiring Up the Controller 150 Implementing the Loading of the Previous Page 150 Exercise: Finishing the Controller 150 Solution: Finishing the Controller 151 Awake from Nib 152 Disabling and Enabling the Buttons 153 Still Needs Work 156 Customizing with Delegates 158 Understanding Delegates 158 The Default Window Behavior 162 Turning the Background Red 162 Exercise: Turning the Background Green 165 Solution: Turning the Background Green 165 Application Delegate 165 Delegates for Your Web View 166 Setting the Window Title 167 Exercise: Updating the URL and Setting Buttons 169 Solution: Updating the URL and Setting Buttons 170 Cleaning Up 170 Exercise: Adding a Progress Indicator 173 Solution: Adding a Progress Indicator 173 Adapting Our Browser to the iPhone 175 Creating the iPhone Project 175 Creating the Look of Our Browser 177 The WebView's Limitations 178 Loading a Web Page at Launch 179 Tweaking the Text Field in IB 181 Using the Text Field Delegate 183 Using a Third Delegate to Implement the Buttons 184 Exercise: Adding an Activity Indicator 185 Solution: Adding an Activity Indicator 186 Organizing with Pragma Marks 188 Posting and Listening for Notifications 191 Exercise: Creating a Model 192 Solution: Creating a Model 192 Registering for Notifications 194 Responding to Workspace Activity 195 Holding on to the Controller 197 Exercise: Registering for Notifications 198 Solution: Registering for Notifications 198 Posting Notifications 199 Exercise: Receiving the Custom Notifications 201 Solution: Receiving the Custom Notifications 201 Creating Protocols for Delegation 203 Exercise: Creating and Setting the Delegate 204 Solution: Creating and Setting the Delegate 204 Creating and Using a Protocol 205 Requiring Methods 207 Responding to Selector 208 Exercise: Calling the Delegate Methods 208 Solution: Calling the Delegate Methods 209 Exercise: Cleaning Up 209 Solution: Cleaning Up 209 Working with Dictionaries 213 Looking at the User Info 213 Reading from a Dictionary 214 Exercise: Displaying the Name 215 Solution: Displaying the Name 215 Reducing Redundancy 216 Using a Dictionary for Flow Control 218 Adding and Removing Entries with a Mutable Dictionary 218 Exercise: Adding an Icon 221 Solution: Adding an Icon 223 Multiple Nibs 227 Methods, Objects, and Nibs 227 Splitting Nibs 229 Preparing to Split Out the View 231 Creating the View Nib 232 Integrating a Nib File 233 The File's Owner 235 Exercise: Loading the View 236 Solution: Loading the View 237 Creating the Window Nib 237 Loading the Window Nib 239 Presenting the Window 240 Exercise: Connecting the View and the Model 240 Solution: Connecting the View and the Model 241 Creating Custom Views 243 Creating a Custom View 243 Drawing Shapes into a Custom View 245 Exercise: Changing the Stroke Color 248 Solution: Changing the Stroke Color 248 Drawing Images 250 Drawing Text 252 Displaying Data in a Table 256 Tables and Data Sources 256 Exercise: Implementing a Basic Data Source 259 Solution: Implementing a Basic Data Source 260 Exercise: Introducing a Data Source 261 Solution: Introducing a Data Source 262 Filling Cells Based on Table Column Titles 263 Table Column Identifiers as Keys 265 Previews of Coming Attractions 266 Exercise: Adding and Removing Rows 266 Solution: Adding and Removing Rows 267 Manually Removing Rows 268 Saving Data to Disk 270 Saving in Your Running Application 270 Where to Put Application Support 273 Saving to a Plist 274 Reading a Plist 275 Saving an Archive to Disk 276 Reading and Using Preferences 278 Setting the Factory Defaults 278 Preparing to Set User Defaults 280 The Preference Window Nib 281 Enabling the Preferences Window 283 Changing Views 285 Working with Radio Buttons 285 Adding Preferences for View at Launch 287 Exercise: Launching with the Right View 288 Solution: Launching with the Right View 288 Eliminating Magic Numbers 290 Customizing the Menu Bar 292 Moving the Main Window 293 Exercise: Switching Views (Mostly) 294 Solution: Switching Views (Mostly) 294 Lazy Initialization 296 Key Value Coding 298 Treating Objects Like Dictionaries 299 Getting Variables Using KVC 301 Undefined Keys 303 Exercise: Setting Variables Using KVC 304 Solution: Setting Variables Using KVC 304 KVC and Dictionaries 305 Keypaths for Navigating a Class Hierarchy 306 Exercise: Filling Tables Using KVC 309 Solution: Filling Tables Using KVC 309 Arrays and KVC 311 Key Value Observing 314 Codeless Connections 314 A Target-Action Counter 316 Introducing an Observer 318 Registering an Observer 320 Making Changes Observable 321 Observing the Changes 323 Exercise: Adding a Second Observer 324 Solution: Adding a Second Observer 324 The Ugly Way to Observe More Than One Attribute 325 Selecting Methods Using KVC 328 Implementing an Observer Object 329 Updating Dependent Variables 331 Cocoa Bindings 334 The Model and View for Our Counter with Bindings 335 Creating and Connecting the NSObjectController 335 Binding More Objects 338 Number Formatters 339 Exercise: Connecting Two Counters with Bindings 341 Solution: Connecting Two Counters with Bindings 342 The Model for Our Bookshelf Example 344 Creating the View for the Bookshelf 345 Binding with the NSArrayController 346 The Big Finish 349 Core Data 350 Entities and Attributes 351 Using the Core Data Widget 352 The Managed Object Context 354 The Persistence Layer 356 Introducing Relationships 358 Choosing a Relationship's Delete Rule 360 Updating the View 361 Managing Dependencies 362 Exercise: Enabling Author Addition and Removal 363 Sorting 363 Filtering Items 365 Coding the Sort Descriptor 366 Categories 368 Overcoming Limitations 368 Creating a Category 369 Category Cautions 371 Private Methods in Class Extensions 372 Exercise: Extending Properties with Class Extensions 375 Solution: Extending Properties with Class Extensions 375 Categories and Core Data 376 Generated Classes in Core Data 378 Accessing Properties 379 Regenerating Class Files from Entities 380 Blocks 383 The Need for Blocks in Wrappers 384 Declaring a Block 385 Using Blocks in Wrappers 386 Capturing Values 387 Blocks and Collections 389 Declaring, Defining, and Using Blocks 390 Using __block 392 Cleaning Up with typedef 393 Exercise: Using Blocks in Callbacks 394 Solution: Using Blocks in Callbacks 396 Operations and Their Queues 398 Making the Beach Ball Spin 398 Invocation Operations 400 Block Operations 402 Interacting with the Queue and Operations 403 Custom NSOperations 406 From Operation Queues to Dispatch Queues 408 Dispatch Queues 412 When to Use Dispatch Queues 412 Quick Queue Overview 414 Drawing Our Fractal 415 Working Without Dispatch Queues 416 The Main Queue 418 Global Concurrent Queues 419 Synchronizing on the Main Queue 420 Private Dispatch Queues 421 Synchronous Tasks 422 Up and Out 426 But What About... 426 What's Next 427 Acknowledgments 428 Dedication 429 Bibliography 431 Index 434 Symbols 434 A 434 B 435 C 435 D 437 E 438 F 439 G 439 H 439 I 439 K 440 L 440 M 441 N 442 O 443 P 444 Q 445 R 445 S 446 T 447 U 447 V 447 W 448 X 448 Y 448 Z 449

Cocoa Programming: A Quick-Start Guide for Developers shows you how to get productive with Cocoa-fast! We won't walk you through every class and method in the API (but we will show you where to find that information). Instead, we'll jump right in and start building a web browser using Cocoa. In just a few minutes you'll have something that works. A couple of minutes more, and you'll have code in your custom controller, listening for notifications and call-backs. Soon you'll have the functionality you'd expect in a full browser. And that's just the first few chapters...

Apple's Cocoa frameworks let you write powerful and attractive applications for Mac OS X or the iPhone. With this book plus your existing knowledge of object-oriented programming you can take advantage of Cocoa and create compelling, feature rich, compliant Mac applications for this industry-leading environment
دانلود کتاب Cocoa Programming: A Quick-Start Guide for Developers (Pragmatic Programmers)