Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Declarations

Dynamically type objects by declaring them as id.

id myObject;

Since the class of dynamically typed objects is resolved at runtime, you can refer to them in your code without knowing beforehand what class they belong to. Type outlets and objects in this way if they are likely to be involved in polymorphism and dynamic binding.

Statically type objects as a pointer to a class.

NSString* mystring;

You statically type objects to obtain better compile-time type checking and to make code easier to understand.

Declarations of instance methods begin with a minus sign (-); a space after the minus sign is optional.

- (NSString*)countryName;

Put the type of value returned by a method in parentheses between the minus sign (or plus sign for class methods) and the beginning of the method name. Methods that return nothing must have a return type of void.

Method argument types are in parentheses and go between the argument’s keyword and the argument itself.

- (id)initWithName:(NSString*)name andType:(int)type;

Be sure to terminate all declarations with a semicolon.

By default, the scope of an instance variable is protected, making that variable directly accessible only to objects of the class that declares it or of a subclass of that class. To make an instance variable private (accessible only within the declaring class), insert the @private compiler directive before the declaration.



< Previous PageNext Page > Hide TOC


Last updated: 2007-10-31




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice