没有合适的资源?快使用搜索试试~ 我知道了~
The Objective-C 2.0 Programming Language
4星 · 超过85%的资源 需积分: 10 196 下载量 11 浏览量
2009-01-05
15:53:08
上传
评论
收藏 1.12MB PDF 举报
温馨提示
试读
133页
The Objective-C 2.0 Programming Language
资源推荐
资源详情
资源评论
The Objective-C 2.0 Programming Language
Cocoa > Objective-C Language
2008-11-19
Apple Inc.
© 2008 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in
any form or by any means, mechanical,
electronic, photocopying, recording, or
otherwise, without prior written permission of
Apple Inc., with the following exceptions: Any
person is hereby authorized to store
documentation on a single computer for
personal use only and to print copies of
documentation for personal use provided that
the documentation contains Apple’s copyright
notice.
The Apple logo is a trademark of Apple Inc.
Use of the “keyboard” Apple logo
(Option-Shift-K) for commercial purposes
without the prior written consent of Apple may
constitute trademark infringement and unfair
competition in violation of federal and state
laws.
No licenses, express or implied, are granted
with respect to any of the technology described
in this document. Apple retains all intellectual
property rights associated with the technology
described in this document. This document is
intended to assist application developers to
develop applications only for Apple-labeled
computers.
Every effort has been made to ensure that the
information in this document is accurate. Apple
is not responsible for typographical errors.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
Apple, the Apple logo, Bonjour, Cocoa, Mac,
Mac OS, Objective-C, and Xcode are trademarks
of Apple Inc., registered in the United States
and other countries.
iPhone is a trademark of Apple Inc.
Java and all Java-based trademarks are
trademarks or registered trademarks of Sun
Microsystems, Inc. in the U.S. and other
countries.
Times is a registered trademark of Heidelberger
Druckmaschinen AG, available from Linotype
Library GmbH.
Simultaneously published in the United States
and Canada.
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
THIS DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS
PROVIDED “AS IS,” AND YOU, THE READER, ARE
ASSUMING THE ENTIRE RISK AS TO ITS QUALITY
AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES RESULTING FROM ANY
DEFECT OR INACCURACY IN THIS DOCUMENT, even
if advised of the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple
dealer, agent, or employee is authorized to make
any modification, extension, or addition to this
warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have
other rights which vary from state to state.
Contents
Introduction
Introduction to The Objective-C 2.0 Programming Language 9
Who Should Read This Document 9
Organization of This Document 10
Conventions 11
See Also 11
Runtime 11
Memory Management 12
Chapter 1
Objects, Classes, and Messaging 13
Runtime 13
Objects 13
Object Basics 13
id 14
Dynamic Typing 14
Memory Management 15
Object Messaging 15
Message Syntax 15
Sending Messages to nil 17
The Receiver’s Instance Variables 18
Polymorphism 18
Dynamic Binding 19
Dynamic Method Resolution 19
Dot Syntax 19
Classes 24
Inheritance 24
Class Types 27
Class Objects 29
Class Names in Source Code 33
Testing Class Equality 34
Chapter 2
Defining a Class 35
Source Files 35
Class Interface 35
Importing the Interface 37
Referring to Other Classes 37
The Role of the Interface 38
Class Implementation 38
Referring to Instance Variables 39
The Scope of Instance Variables 40
3
2008-11-19 | © 2008 Apple Inc. All Rights Reserved.
Messages to self and super 43
An Example 44
Using super 45
Redefining self 46
Chapter 3
Allocating and Initializing Objects 47
Allocating and Initializing Objects 47
The Returned Object 47
Implementing an Initializer 48
Constraints and Conventions 48
Handling Initialization Failure 50
Coordinating Classes 51
The Designated Initializer 53
Combining Allocation and Initialization 55
Chapter 4
Declared Properties 57
Overview 57
Declared Properties 57
Property Declaration and Implementation 58
Property Declaration 58
Property Declaration Attributes 59
Markup and Deprecation 61
Property Implementation Directives 61
Using Properties 63
Property Re-declaration 63
Copy 63
dealloc 64
Core Foundation 65
Example 65
Subclassing with Properties 67
Performance and Threading 67
Runtime Difference 68
Chapter 5
Categories and Extensions 69
Adding Methods to Classes 69
How you Use Categories 70
Categories of the Root Class 71
Extensions 71
Chapter 6
Protocols 73
Declaring Interfaces for Others to Implement 73
Methods for Others to Implement 74
4
2008-11-19 | © 2008 Apple Inc. All Rights Reserved.
CONTENTS
Declaring Interfaces for Anonymous Objects 75
Non-Hierarchical Similarities 75
Formal Protocols 76
Declaring a Protocol 76
Optional Protocol Methods 76
Informal Protocols 77
Protocol Objects 78
Adopting a Protocol 78
Conforming to a Protocol 79
Type Checking 79
Protocols Within Protocols 80
Referring to Other Protocols 81
Chapter 7
Fast Enumeration 83
The for…in Feature 83
Adopting Fast Enumeration 83
Using Fast Enumeration 84
Chapter 8
Enabling Static Behavior 87
Static Typing 87
Type Checking 88
Return and Argument Types 89
Static Typing to an Inherited Class 89
Chapter 9
Selectors 91
Methods and Selectors 91
SEL and @selector 91
Methods and Selectors 92
Method Return and Argument Types 92
Varying the Message at Runtime 92
The Target-Action Design Pattern 93
Avoiding Messaging Errors 93
Chapter 10
Exception Handling 95
Handling Exceptions 95
Throwing Exceptions 96
Processing Exceptions 96
Chapter 11
Threading 99
Synchronizing Thread Execution 99
5
2008-11-19 | © 2008 Apple Inc. All Rights Reserved.
CONTENTS
剩余132页未读,继续阅读
资源评论
- LL09032013-07-19还可以,但只是入门,一些高级的东西没有说,还得去看官方文档。
- bamboo9876543212013-06-04教程不错, 简单明了
kittyjie
- 粉丝: 237
- 资源: 1615
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功