在接口中声明属性之间的区别

Difference between declaring properties in interface

谁能告诉我在这样的界面中声明 属性 有什么区别

@interface RootViewController : UITableViewController {
  NSDate *timestamp;
}
@end

@interface RootViewController : UITableViewController 
@property (nonatomic, retain) NSDate *timestamp;
@end

@interface RootViewController : UITableViewController {
  NSDate *timestamp;
}
@property (nonatomic, retain) NSDate *timestamp;

前者根本不是 属性。这是一个实例变量声明。

后者是 属性,它是 getter/setter 对及其支持实例变量的术语。

为您合成的实例变量将带有 _ 前缀。因此,如果您使用 Objective C 运行时 API 查看 RootViewController,您可以看到它实际上有一个名为 _timestamp.

的 ivar