Method return values
Objective C docs from apple says
For the object-oriented constructs of Objective-C, such as method return values, id replaces int as the default data type. (For strictly C constructs, such as function return values, int remains the default type.)
I thought the return type and hence value is something predefined in method signature. So could you give me some example o开发者_JS百科n what the doc refers to?
That line simply means that a method written as such, would, by default, return id
:
- init { ... }
or
+ array { ... }
versus
- (id)init { ... }
In addition, a method written without explicit parameter types will take in id
objects.
- initWithObject:object { ... }
is the same as
- (id)initWithObject:(id)object { ... }
精彩评论