Book description
Covering the bulk of what you need to know to develop full-featured applications for OS X, this edition is updated for OS X Yosemite (10.10), Xcode 6, and Swift. Written in an engaging tutorial style and class-tested for clarity and accuracy, it is an invaluable resource for any Mac programmer. The authors introduce the two most commonly used Mac developer tools: Xcode and Instruments. They also cover the Swift language, basic application architecture, and the major design patterns of Cocoa. Examples are illustrated with exemplary code, written in the idioms of the Cocoa community, to show you how Mac programs should be written.
After reading this book, you will know enough to understand and utilize Apple’s online documentation for your own unique needs. And you will know enough to write your own stylish code.
This edition was written for Xcode 6.3 and Swift 1.2. At WWDC 2015, Apple announced Xcode 7 and Swift 2, both of which introduce significant updates that (along with some changes to Cocoa for OS X 10.11) affect some of the exercises in this book. We have prepared a companion guide listing the changes needed to use Xcode 7 to work through the exercises in the book; it is available at https://github.com/bignerdranch/cocoa-programming-for-osx-5e/blob/master/Swift2.md.
Table of contents
- Title Page
- Dedication
- Acknowledgments
- Table of Contents
- Introduction
- 1. Let’s Get Started
- 2. Swift Types
- 3. Structures and Classes
- 4. Memory Management
- 5. Controls
- 6. Delegation
- 7. Working with Table Views
- 8. KVC, KVO, and Bindings
-
9. NSArrayController
- RaiseMan’s Model Layer
- RaiseMan’s View Layer
- Introducing NSArrayController
- Adding an Array Controller to the XIB
- Binding the Array Controller to the Model
- Binding the Table View’s Content to the Array Controller
- Connecting the Add Employee Button
- Binding the Text Fields to the Table Cell Views
- Formatting the Raise Text Field
- Connecting the Remove Button
- Binding the Table View’s Selection to the Array Controller
- Configuring RaiseMan’s Remove Button
- Sorting in RaiseMan
- How Sorting Works in RaiseMan
- For the More Curious: The caseInsensitiveCompare(_:) Method
- For the More Curious: Sorting Without NSArrayController
- For the More Curious: Filtering
- For the More Curious: Using Interface Builder’s View Hierarchy Popover
- Challenge: Sorting Names by Length
- 10. Formatters and Validation
- 11. NSUndoManager
-
12. Archiving
- NSCoder and NSCoding
- The Document Architecture
- Saving and NSKeyedArchiver
- Loading and NSKeyedUnarchiver
- Setting the Extension and Icon for the File Type
- Application Data and URLs
- For the More Curious: Preventing Infinite Loops
- For the More Curious: Creating a Protocol
- For the More Curious: Automatic Document Saving
- For the More Curious: Document-Based Applications Without Undo
- For the More Curious: Universal Type Identifiers
-
13. Basic Core Data
- Defining the Object Model
- Configure the Array Controller
- Add the Views
- Connections and Bindings
- How Core Data Works
- Fetching Objects from the NSManagedObjectContext
- Persistent Store Types
- Choosing a Cocoa Persistence Technology
- Customizing Objects Created by NSArrayController
- Challenge: Begin Editing on Add
- Challenge: Implement RaiseMan Using Core Data
-
14. User Defaults
- NSUserDefaults
- Adding User Defaults to SpeakLine
- Create Names for the Defaults
- Register Factory Defaults for the Preferences
- Reading the Preferences
- Reflecting the Preferences in the UI
- Writing the Preferences to User Defaults
- Storing the User Defaults
- What Can Be Stored in NSUserDefaults?
- Precedence of Types of Defaults
- What is the User’s Defaults Database?
- For the More Curious: Reading/Writing Defaults from the Command Line
- For the More Curious: NSUserDefaultsController
- Challenge: Reset Preferences
- 15. Alerts and Closures
-
16. Using Notifications
- What Notifications Are
- What Notifications Are Not
- NSNotification
- NSNotificationCenter
- Starting the Chatter Application
- Using Notifications in Chatter
- For the More Curious: Delegates and Notifications
- Challenge: Beep-beep!
- Challenge: Add Usernames
- Challenge: Colored Text
- Challenge: Disabling the Send Button
-
17. NSView and Drawing
- Setting Up the Dice Application
- Views, Rectangles, and Coordinate Systems
- Custom Drawing
- Saving and Restoring the Graphics State
- Cleaning up with Auto Layout
- Drawing Images
- Scroll Views
- Creating Views Programmatically
- For the More Curious: Core Graphics and Quartz
- For the More Curious: Dirty Rects
- For the More Curious: Flipped Views
- Challenge: Gradients
- Challenge: Stroke
- Challenge: Make DieView Configurable from Interface Builder
- 18. Mouse Events
- 19. Keyboard Events
- 20. Drawing Text with Attributes
- 21. Pasteboards and Nil-Targeted Actions
- 22. Drag-and-Drop
- 23. NSTimer
- 24. Sheets
-
25. Auto Layout
- What is Auto Layout?
- Adding Constraints to RaiseMan
- Intrinsic Content Size
- Creating Layout Constraints Programmatically
- Visual Format Language
- Does Not Compute, Part 1: Unsatisfiable Constraints
- Does Not Compute, Part 2: Ambiguous Layout
- For the More Curious: Autoresizing Masks
- Challenge: Add Vertical Constraints
- Challenge: Add Constraints Programmatically
-
26. Localization and Bundles
- Different Mechanisms for Localization
- Localizing a XIB File
- Localizing String Literals
- Demystifying NSLocalizedString and genstrings
- Explicit Ordering of Tokens in Format Strings
- NSBundle
- For the More Curious: Localization and Plurality
- Challenge: Localizing the Default Name for a Newly Added Employee
- Challenge: Localizing the Undo Action Names
- 27. Printing
- 28. Web Services
-
29. Unit Testing
- Testing in Xcode
- Your First Test
- A Note on Literals in Testing
- Creating a Consistent Testing Environment
- Sharing Constants
- Refactoring for Testing
- For the More Curious: Access Modifiers
- For the More Curious: Asynchronous Testing
- Challenge: Make Course Implement Equatable
- Challenge: Improve Test Coverage of Web Service Responses
- Challenge: Test Invalid JSON Dictionary
-
30. View Controllers
- NSViewController
- Starting the ViewControl Application
- Windows, Controllers, and Memory Management
- Container View Controllers
- Add a Tab View Controller
- View Controllers vs. Window Controllers
- Considerations for OS X 10.9 and Earlier
- Challenge: SpeakLineViewController
- Challenge: Programmatic View Controller
- Challenge: Add a Window Controller
- 31. View Swapping and Custom Container View Controllers
- 32. Storyboards
- 33. Core Animation
- 34. Concurrency
- 35. NSTask
- 36. Distributing Your App
- 37. Afterword
- Index
Product information
- Title: Cocoa Programming for OS X: The Big Nerd Ranch Guide
- Author(s):
- Release date: April 2015
- Publisher(s): Big Nerd Ranch Guides
- ISBN: 9780134077130
You might also like
book
Learning Cocoa with Objective-C, 4th Edition
Get up to speed on Cocoa and Objective-C, and start developing applications on the iOS and …
book
Learn Cocoa on the Mac, Second Edition
The Cocoa frameworks are some of the most powerful for creating native OS X apps available …
book
iOS and macOS™ Performance Tuning: Cocoa®, Cocoa Touch®, Objective-C®, and Swift™
In Marcel Weiher drills down to the code level to help you systematically optimize CPU, memory, …
book
Cocoa and Objective-C: Up and Running
Build solid applications for Mac OS X, iPhone, and iPod Touch, regardless of whether you have …