17
我无法理解何时使用Objective C 2.0中的属性。看起来你不需要一个原始类型的属性,例如:int,bool,float。这是真的?我看过一些例子显示这些类型的属性,其他的将它们排除在外。例如,在苹果公司的代码示例他们有:对原始类型使用属性
...
@interface Book : NSObject {
// Primary key in the database.
NSInteger primaryKey;
// Attributes.
NSString *title;
NSDate *copyright;
NSString *author;
BOOL hydrated;
BOOL dirty;
NSData *data;
}
@property (assign, nonatomic, readonly) NSInteger primaryKey;
// The remaining attributes are copied rather than retained because they are value objects.
@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSDate *copyright;
@property (copy, nonatomic) NSString *author;
...
Apple SQLite Book List Sample Code
所以你可以看到,他们不使用属性BOOL,但他们对待它拥有遍布实现文件的实例变量,读取数值并设定数值。 在线搜索我已经找到了使用这些类型属性的教程,例如:(@property BOOL flag)。有人能帮我解释一下这个话题吗?谢谢。
谢谢Marc.Yeah,我几乎所有的东西都使用了属性,只是通过我的课程进行清理,并确保它是正确的。我在我的问题中添加了指向我提到的Apple示例代码的链接。但似乎他们直接访问它(不通过self.dirty) – Sean 2009-01-08 16:59:04