Example: dental hygienist

The Objective-C Programming Language - Clemson University

Inside Mac OS X The Objective-C Programming Language February 2003 Apple Computer, Inc. 2002 Apple Computer, 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 Computer, 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.

6 Apple Computer, Inc. February 2003 CONTENTS Using C++ With Objective-C 122 Mixing Objective-C and C++ Language Features 122 C++ Lexical Ambiguities and Conflicts 125

Tags:

  Programming, Objectives, Objective c, Objective c programming

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of The Objective-C Programming Language - Clemson University

1 Inside Mac OS X The Objective-C Programming Language February 2003 Apple Computer, Inc. 2002 Apple Computer, 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 Computer, 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.

2 The Apple logo is a trademark of Apple Computer, 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 book. Apple retains all intellectual property rights associated with the technology described in this book. This book is intended to assist application developers to develop applications only for Apple-labeled or Apple-licensed effort has been made to ensure that the information in this document is accurate.

3 Apple is not responsible for typographical Computer, Infinite LoopCupertino, CA 95014408-996-1010 Apple, the Apple logo, and Macintosh are trademarks of Apple Computer, Inc., registered in the United States and other is a trademark of Sun Microsystems, published in the United States and Canada. Even though Apple has reviewed this manual, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS MANUAL, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS MANUAL IS SOLD AS IS, AND YOU, THE PURCHASER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS MANUAL, even if advised of the possibility of such WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED.

4 No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this 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. 3 Apple Computer, Inc. February 2003 Contents Figures, Listings, and Tables11 Chapter 1 Introduction The Development Environment14 Why Objective-C15 How This Book is Organized16 Conventions17 Chapter 2 Object-Oriented Programming Interface and Implementation20 The Object Model24 The Messaging Metaphor26 Classes28 Modularity29 Reusability30 Mechanisms Of Abstraction31 Encapsulation32 Polymorphism33 Inheritance35 Class Hierarchies35 Subclass Definitions36 Uses of Inheritance37 Dynamism39 Dynamic Typing39 Dynamic Binding40 Dynamic Loading43 Structuring Programs44 Outlet Connections45 4 Apple

5 Computer, Inc. February 2003 CONTENTS Extrinsic and Intrinsic Connections47 Activating the Object Network47 Aggregation and Decomposition48 Models and Frameworks49 Structuring the Programming Task50 Collaboration51 Organizing Object-Oriented Projects52 Designing on a Large Scale52 Separating the Interface from the Implementation52 Modularizing the Work52 Keeping the Interface Simple53 Making Decisions Dynamically53 Inheriting Generic Code53 Reusing Tested Code54 Chapter 3 The Objective-C Language Objective-C Objects55id56 Dynamic Typing57 Object

6 Messaging58 The Receiver s Instance Variables59 Polymorphism60 Dynamic Binding60 Classes62 Inheritance62 The NSObject Class64 Inheriting Instance Variables64 Inheriting Methods65 Overriding One Method With Another66 Abstract Classes66 Class Types67 Static Typing67 Type Introspection68 Class Objects68 Creating Instances70 Customization With Class Objects71 CONTENTS 5 Apple Computer, Inc. February 2003 Variables and Class Objects72 Initializing a Class Object73 Methods of the Root Class74 Class Names in Source Code74 Defining a Class75 The Interface76 Importing the Interface78 Referring to Other Classes79 The Role of the Interface79 The Implementation80 Referring to Instance Variables82 The Scope of Instance Variables83 How Messaging Works87 Selectors90 Methods and Selectors91 Method Return and Argument Types91 Varying the Message at Runtime92 The Target-Action Paradigm92 Avoiding Messaging Errors94 Hidden Arguments94

7 Messages to self and super95An Example96 Using super99 Redefining self99 Extending Classes101 Categories Adding Methods to Existing Classes101 Adding to a Class102 How Categories Are Used103 Categories of the Root Class103 Protocols Declaring Interfaces for Others to Implement104 When to Use Protocols105 Enabling Static Behaviors115 Static Typing116 Type Checking117 Return and Argument Types118 Static Typing to an Inherited Class118 Getting a Method Address120 Getting an Object Data Structure120 6 Apple Computer, Inc. February 2003 CONTENTS Using C++ With Objective-C122 Mixing Objective-C and C++ Language Features122C++ Lexical Ambiguities and Conflicts125 Chapter 4 The Objective-C Runtime System Memory Management129 Allocating and Initializing Objects129 The Returned Object130 Arguments131 Coordinating Classes132 The Designated Initializer134 Combining Allocation and Initialization139 Retaining Objects140 Handling Cyclical References141 Deallocation142 Releasing Shared Objects143 Releasing Instance Variables144 Marking Objects for Later

8 Release144 Object Ownership145 Forwarding146 Forwarding and Multiple Inheritance149 Surrogate Objects150 Forwarding and Inheritance150 Dynamic Loading152 Remote Messaging152 Distributed Objects153 Language Support155 Synchronous and Asynchronous Messages156 Pointer Arguments157 Proxies and Copies159 Type Encodings160 Chapter 5 Objective-C Runtime Functions and Data Structures Objective-C Functions165 CONTENTS 7 Apple Computer, Inc. February 2003 Accessing Selectors166sel_getName166sel_isMapped16 7sel_registerName167sel_getUid168 Sending Messages168objc_msgSend169objc_msgSend_s tret169objc_msgSendSuper170objc_msgSendS uper_stret171 Forwarding Messages172objc_msgSendv172objc_msgSendv _stret173marg_malloc173marg_free174marg_ getRef174marg_getValue174marg_setValue17 5 Adding Classes175objc_addClass175 Accessing

9 Methods178class_getInstanceMethod178clas s_getClassMethod179class_nextMethodList1 79class_addMethods180class_removeMethods 181method_getNumberOfArguments182method_ getSizeOfArguments182method_getArgumentI nfo182 Accessing Instance Variable Definitions183class_getInstanceVariable1 83 Accessing the Class Version183class_setVersion183class_getVe rsion184 Posing As Another Class185class_poseAs185 Obtaining Class Definitions185objc_getClassList186 8 Apple Computer, Inc. February 2003 CONTENTS objc_getClass187objc_lookUpClass188objc_ getMetaClass188objc_setClassHandler189 Instantiating Classes189class_createInstance189class_c reateInstanceFromZone190 Accessing Instance Variables190object_setInstanceVariable19 1object_getInstanceVariable191 Objective-C Callbacks192 Class Handler Callback192 Objective-C Data Types192 Class Definition Data Structures193objc_class194objc_ivar196ob jc_ivar_list197objc_method198objc_method _list199objc_cache200objc_protocol_list2 01 Instance Data

10 Types201objc_object202objc_super202 Appendix A Objective-C Language Summary Messages205 Defined Types206 Preprocessor Directives207 Compiler Directives207 Classes208 Categories209 Formal Protocols210 Method Declarations211 Method Implementations212 Naming Conventions212 CONTENTS 9 Apple Computer, Inc. February 2003 Appendix B Grammar for the Objective-C Language External Declarations217 Type Specifiers221 Type Qualifiers222 Primary Expressions222 Chapter C Document Revision History Glossary 227 Index 233


Related search queries