Apple 的 Objective C 文档说
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.)
我认为返回类型和值是方法签名中预定义的东西。那么,您能否举例说明该文档所指的内容?
最佳答案
该行仅表示这样编写的方法在默认情况下会返回 id
:
- init { ... }
或
+ array { ... }
对比
- (id)init { ... }
此外,没有显式参数类型编写的方法将接收 id
对象。
- initWithObject:object { ... }
与
相同- (id)initWithObject:(id)object { ... }
关于objective-c - 方法返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6560981/