【发布时间】:2009-09-07 12:25:07
【问题描述】:
我一直想知道关于属性的事情。在使用属性时,是否需要覆盖发布消息以确保属性是已发布的属性?
即以下(虚构的)示例是否足够?
@interface MyList : NSObject {
NSString* operation;
NSString* link;
}
@property (retain) NSString* operation;
@property (retain) NSString* link;
@end
@implementation MyList
@synthesize operation,link;
@end
【问题讨论】:
-
因为 NSString 确认到 NSCopying 协议,所以最好使用 @property (copy, readwrite) NSString *操作另外,如果你使用现代运行时,你不需要指定实例变量:它们也将被合成。要了解更多信息,请搜索 Apple 的“Objective-C 2.0 编程指南”并查找名为“Property Declaration Attributes”和“Property Implementation Directives”的部分。
-
+1 个很好的问题,想知道同样的事情
标签: objective-c cocoa