objective-c - 方法返回值

标签 objective-c

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/

相关文章:

objective-c - 指针在 Objective-C 中是如何工作的

objective-c - 这个工具栏样式的 Cocoa UI 元素是什么?

ios - NSAttributedString 中缺少 Unicode 字符

iphone - iOS获取视频帧率

ios - 由于联系委托(delegate)断言失败导致游戏崩溃

objective-c - 我如何将文本字段单元格(在 cocoa 中)中的文本复制到 NSPasteboard?

objective-c - Cocoa 命令行工具方法声明

objective-c - 防止 iCloud 打开文件对话框在 OS X 启动时出现

ios - 如何更改表单元格中的 UIImageView 图像,单击单元格中的按钮?

ios - 如何检测图像中的透明区域?