ios - 接口(interface)声明中@property和变量之间的区别

标签 ios objective-c cocoa-touch cocoa

将变量放在 @interface{} 中有何区别?在头文件中声明,并放入 @property在该声明之后?

例如,

@interface GameCenterManager : NSObject
{
GKInvite* pendingInvite;
}
@end

相对于

@interface GameCenterManager : NSObject
@property (weak, nonatomic) GKInvite* pendingInvite
@end

最佳答案

Declaring a property generates getters and setters for the instance variable, according to the criteria within the parenthesis.

Defining the variables in the brackets simply declares them instance variables.

以下是一些提供更多信息的链接。

http://www.cocoawithlove.com/2010/03/dynamic-ivars-solving-fragile-base.html

Is there a difference between an "instance variable" and a "property" in Objective-c?

http://iphonedevelopment.blogspot.in/2008/12/outlets-property-vs-instance-variable.html

关于ios - 接口(interface)声明中@property和变量之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16661911/

相关文章:

objective-c - 为什么在单元测试中使用 UITableViewCell 会导致 Trace/BPT 陷阱?

ios - 使用 JSON 进行基本身份验证

iOS UIView 渲染到纹理——保持质量

ios - Today ViewController 的主视图右移

objective-c - 怎样才能让下面的代码变干呢?

iphone - 操作无法完成。 ( cocoa 错误 1560。)

iphone - 无法执行 segue

cocoa-touch - 使用 CGContext* 函数时出现“无效上下文 0x0”错误

ios - 如何使用FTP直接从iOS将图像上传到服务器目录

android - 在 React Native 中使用 python 库