没有合适的资源?快使用搜索试试~ 我知道了~
Programming.With.Objective.C
5星 · 超过95%的资源 需积分: 0 11 下载量 122 浏览量
2013-01-27
23:51:52
上传
评论
收藏 1.74MB PDF 举报
温馨提示
试读
128页
Programming.With.Objective.C
资源推荐
资源详情
资源评论
Programming with
ObjectiveC
Contents
About Objective-C 7
At a Glance 7
An App Is Built from a Network of Objects 7
Categories Extend Existing Classes 8
Protocols Define Messaging Contracts 8
Values and Collections Are Often Represented as ObjectiveC Objects 8
Blocks Simplify Common Tasks 9
Error Objects Are Used for Runtime Problems 9
ObjectiveC Code Follows Established Conventions 9
Prerequisites 10
See Also 10
Defining Classes 11
Classes Are Blueprints for Objects 11
Mutability Determines Whether a Represented Value Can Be Changed 12
Classes Inherit from Other Classes 12
The Root Class Provides Base Functionality 14
The Interface for a Class Defines Expected Interactions 15
Basic Syntax 15
Properties Control Access to an Object’s Values 15
Method Declarations Indicate the Messages an Object Can Receive 17
Class Names Must Be Unique 19
The Implementation of a Class Provides Its Internal Behavior 20
Basic Syntax 21
Implementing Methods 21
ObjectiveC Classes Are also Objects 22
Exercises 23
Working with Objects 24
Objects Send and Receive Messages 24
Use Pointers to Keep Track of Objects 26
You Can Pass Objects for Method Parameters 27
Methods Can Return Values 28
Objects Can Send Messages to Themselves 30
20120720 | © 2012 Apple Inc. All Rights Reserved.
2
Objects Can Call Methods Implemented by Their Superclasses 31
Objects Are Created Dynamically 34
Initializer Methods Can Take Arguments 36
Class Factory Methods Are an Alternative to Allocation and Initialization 36
Use new to Create an Object If No Arguments Are Needed for Initialization 37
Literals Offer a Concise ObjectCreation Syntax 37
ObjectiveC Is a Dynamic Language 38
Determining Equality of Objects 39
Working with nil 40
Exercises 41
Encapsulating Data 43
Properties Encapsulate an Object’s Values 43
Declare Public Properties for Exposed Data 43
Use Accessor Methods to Get or Set Property Values 44
Dot Syntax Is a Concise Alternative to Accessor Method Calls 45
Most Properties Are Backed by Instance Variables 46
Access Instance Variables Directly from Initializer Methods 48
You Can Implement Custom Accessor Methods 51
Properties Are Atomic by Default 52
Manage the Object Graph through Ownership and Responsibility 53
Avoid Strong Reference Cycles 58
Use Strong and Weak Declarations to Manage Ownership 61
Use Unsafe Unretained References for Some Classes 64
Copy Properties Maintain Their Own Copies 64
Exercises 66
Customizing Existing Classes 68
Categories Add Methods to Existing Classes 68
Avoid Category Method Name Clashes 71
Class Extensions Extend the Internal Implementation 72
Use Class Extensions to Hide Private Information 73
Consider Other Alternatives for Class Customization 75
Interact Directly with the ObjectiveC Runtime 76
Exercises 76
Working with Protocols 77
Protocols Define Messaging Contracts 77
Protocols Can Have Optional Methods 79
Protocols Inherit from Other Protocols 81
20120720 | © 2012 Apple Inc. All Rights Reserved.
3
Contents
Conforming to Protocols 82
Cocoa and Cocoa Touch Define a Large Number of Protocols 83
Protocols Are Used for Anonymity 83
Values and Collections 85
Basic C Primitive Types Are Available in ObjectiveC 85
ObjectiveC Defines Additional Primitive Types 86
C Structures Can Hold Primitive Values 87
Objects Can Represent Primitive Values 87
Strings Are Represented by Instances of the NSString Class 88
Numbers Are Represented by Instances of the NSNumber Class 89
Represent Other Values Using Instances of the NSValue Class 90
Most Collections Are Objects 91
Arrays Are Ordered Collections 92
Sets Are Unordered Collections 96
Dictionaries Collect KeyValue Pairs 97
Represent nil with NSNull 98
Use Collections to Persist Your Object Graph 99
Use the Most Efficient Collection Enumeration Techniques 100
Fast Enumeration Makes It Easy to Enumerate a Collection 100
Most Collections Also Support Enumerator Objects 101
Many Collections Support BlockBased Enumeration 103
Working with Blocks 104
Block Syntax 104
Blocks Take Arguments and Return Values 105
Blocks Can Capture Values from the Enclosing Scope 106
You Can Pass Blocks as Arguments to Methods or Functions 108
Use Type Definitions to Simplify Block Syntax 110
Objects Use Properties to Keep Track of Blocks 111
Avoid Strong Reference Cycles when Capturing self 112
Blocks Can Simplify Enumeration 113
Blocks Can Simplify Concurrent Tasks 115
Use Block Operations with Operation Queues 115
Schedule Blocks on Dispatch Queues with Grand Central Dispatch 116
Dealing with Errors 117
Use NSError for Most Errors 117
Some Delegate Methods Alert You to Errors 117
Some Methods Pass Errors by Reference 118
20120720 | © 2012 Apple Inc. All Rights Reserved.
4
Contents
Recover if Possible or Display the Error to the User 119
Generating Your Own Errors 119
Exceptions Are Used for Programmer Errors 120
Conventions 122
Some Names Must Be Unique Across Your App 122
Class Names Must Be Unique Across an Entire App 122
Method Names Should Be Expressive and Unique Within a Class 123
Local Variables Must Be Unique Within The Same Scope 124
Some Method Names Must Follow Conventions 125
Accessor Method Names Must Follow Conventions 125
Object Creation Method Names Must Follow Conventions 126
Document Revision History 127
20120720 | © 2012 Apple Inc. All Rights Reserved.
5
Contents
剩余127页未读,继续阅读
资源评论
- kingrenato2013-11-11挺好用的,谢谢
zdjnju
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功