没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
The Objective-C Programming Language
Tools & Languages: Objective-C
2010-07-13
Apple Inc.
© 2010 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
.Mac is a registered service mark of Apple Inc.
Apple, the Apple logo, Bonjour, Cocoa,
Instruments, Mac, Mac OS, Objective-C, and
Xcode are trademarks of Apple Inc., registered
in the United States and other countries.
Java is a registered trademark of Oracle and/or
its affiliates
IOS is a trademark or registered trademark of
Cisco in the U.S. and other countries and is used
under license.
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 Programming Language 9
Who Should Read This Document 9
Organization of This Document 10
Conventions 10
See Also 11
Runtime 11
Memory Management 11
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 17
Polymorphism 18
Dynamic Binding 18
Dynamic Method Resolution 19
Dot Syntax 19
Classes 23
Inheritance 23
Class Types 26
Class Objects 27
Class Names in Source Code 32
Testing Class Equality 33
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
2010-07-13 | © 2010 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
Protocols 57
Declaring Interfaces for Others to Implement 57
Methods for Others to Implement 58
Declaring Interfaces for Anonymous Objects 59
Non-Hierarchical Similarities 59
Formal Protocols 60
Declaring a Protocol 60
Optional Protocol Methods 60
Informal Protocols 61
Protocol Objects 62
Adopting a Protocol 62
Conforming to a Protocol 63
Type Checking 63
Protocols Within Protocols 64
Referring to Other Protocols 65
Chapter 5
Declared Properties 67
Overview 67
Property Declaration and Implementation 67
Property Declaration 67
Property Declaration Attributes 68
Property Implementation Directives 71
Using Properties 72
Supported Types 72
Property Re-declaration 72
Copy 73
dealloc 74
Core Foundation 74
4
2010-07-13 | © 2010 Apple Inc. All Rights Reserved.
CONTENTS
Example 75
Subclassing with Properties 76
Performance and Threading 77
Runtime Difference 78
Chapter 6
Categories and Extensions 79
Adding Methods to Classes 79
How you Use Categories 80
Categories of the Root Class 81
Extensions 81
Chapter 7
Associative References 83
Adding Storage Outside a Class Definition 83
Creating Associations 83
Retrieving Associated Objects 84
Breaking Associations 84
Complete Example 84
Chapter 8
Fast Enumeration 87
The for…in Feature 87
Adopting Fast Enumeration 87
Using Fast Enumeration 88
Chapter 9
Enabling Static Behavior 91
Default Dynamic Behavior 91
Static Typing 91
Type Checking 92
Return and Argument Types 93
Static Typing to an Inherited Class 93
Chapter 10
Selectors 95
Methods and Selectors 95
SEL and @selector 95
Methods and Selectors 96
Method Return and Argument Types 96
Varying the Message at Runtime 96
The Target-Action Design Pattern 97
Avoiding Messaging Errors 97
5
2010-07-13 | © 2010 Apple Inc. All Rights Reserved.
CONTENTS
剩余136页未读,继续阅读
资源评论
ken_henderson
- 粉丝: 2
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功