Scott Stevenson,从事Cocoa应用开发八年,此外还拥有六年相关教学经验。他曾创建了风靡一时的Mac编程博客Theocacao,并且于2003年接手Cocoa Dev Central,成为主笔和编辑。他在硅谷组织了多场Cocoa Heads会议,并发表演讲。
目录
Preface
1. Setup and First Run
Download and Install Xcode
Your First Application
Create the Interface
Run the Finished Application
2. Thinking in Code: Basic C
How Code Works
How to Format Code
Variables
Types
Constants
Enumerated Types
Typedefs
Functions
Declaring Functions
Example: First Program
Displaying Values on the Command Line
Compile and Run the Example
Scope
Static Variables
Conditionals
Example: Shopping Trip
Compile and Run
Wrap Up
3. Memory and Pointers: Advanced C
Arrays
Loops
Text Strings
Multidimensional Arrays
Pointers
The Purpose of Pointers
Using Pointers
Pointers and the const Keyword
Dynamic Memory
Strings and Dynamic Memory
Returning Strings from Functions
Arrays of Strings
Example: Address Book
Compile and Run the Address Book Example
Structs
Header Files
Compile and Run the Header File Test Example
Create Files for the Song Struct
Final Example
4. Thinking in Objects
Structs and Classes
Designing Classes
Accessors
Inheritance
Composition
Object Lifetime
Built-in Classes
5. Basic Objective-C
NSString Basics
Using Methods
Nested Method Calls
Multi-Input Methods
Accessors
Dot Syntax
Creating Objects
Basic Memory Management
Using Autorelease Directly
Declaring a Class
Add Methods
Implementing a Class
init
dealloc
Example: PhotoInfo
6. More Objective-C
More on Memory Management
The Life of an Instance Variable
Copying Objects
Class Name Prefixes
Properties
Property Options
64-Bit Objective-C
Enabling 64-Bit
Should I Use 64-Bit?
All Further Examples Assume 64-Bit
Categories
Categories for Private Methods
Introspection
Protocols
Dynamic Messaging
Using Selectors to Call Methods
Forwarding Messages
Exceptions
Example: Data Collector
Some New Classes and Methods
Create the Files
Build and Run
7. Foundation Value Classes
NSString
Ranges and Substrings
Using NSString with C Types
Comparing Strings for Equality
Strings As File Paths
Reading and Writing Files with Strings
Mutability
Advantages of Mutability
Advantages of Immutability
Core Foundation
Memory Management
Core Foundation Mutability
Toll-Free Bridging
Core Foundation Types As Properties
Drawbacks of Core Foundation Types
Open Source
NSNumber
CFNumberRef
Cocoa Primitive Types
NSDecimalNumber
NSNumberFormatter
When to Use Which Number Type
NSData
NSMutableData
NSArray
Fast Enumeration
Blocks
NSMutableArray
CFArrayRef
NSIndexSet
NSDictionary
NSMutableDictionary
CFDictionaryRef
NSSet
NSMutableSet
NSValue
NSDate
CFDateRef
8. Basic Controls
How to Use This Chapter
Windows and Views
Targets and Actions
Buttons
Declaring Action Methods
Connecting Actions
Menus
Responder Chain
Pop-up Buttons
Sliders
Text Fields
Outlets
Datasources
Table View Datasource Methods
Implementing Datasource Methods
Bindings
Key-Value Protocols
Bindings for Simple Controls
Bindings for Complex Controls
Tips for Debugging Bindings
……
9 Designing Applications Using MVX
10 Custom Views and Drawing
11 The Final Word
Index
摘要
Acknowledgments
My education didn't follow the normal path. I taught myself how to program and learned how to run a business mostly by trial and error. In the end, I think this is the only option that would have worked for me, but it was possible only because of my extremely patient and understanding family: my morn, Peggy; my dad, Alan; and my sister, Jamie. You would not be reading this now if it was not for their support. There are so many people that have helped me in my work life, but there are a few that have had a direct impact on this book.
Michael Lopp and Angela Muller were ongoing sources of encouragement and inspiration. This book first came into being over lunch when Michael mentioned something along the lines of “everyone wants an animal on the cover of their book,” referring to the iconic O'Reilly covers. By incredible coincidence, Brian from O'Reilly emailed me about two weeks later. Had Michael not made that comment, this might not have happened.
I had world-class tech reviewers for this project: Joar Wingfors, Michael Jurewitz, Rob Rhyne, and Tim Triemstra. Joar, who I originally met through the tutorials I posted online, tirelessly reviewed an ever-changing book, provided a wealth of essential com- ments and suggestions, and even helped me fix some bugs in the code. He,s one of the most talented engineers I know, and I am thrilled to have been able to get his help on this.
Though he wasn't involved in this project, I owe a lot to John Mora. He has an ability to look an impossibly large task in the face and just do it, despite the usual doubts about whether you know enough or have enough time. It is one of the most impressive traits I know of, and John has it in spades. Thankfully, I think some of that rubbed off on me over the 15 years I've known him.
Thanks to Kip Krueger for patiently helping me figure out the low-level details of memory and offering pointers when I was learning C. His mentoring is the reason I'm able to teach these topics to you now. ……