0
我想知道保留在下面的屬性聲明中有什麼影響(如果有的話)。手動執行的setter將保留該變量。如果手動執行setter,是否需要(保留)?
接口:
@property (nonatomic, retain, setter=setIncident:) Incident * incident;
實現:
- (void)setIncident:(CSIncident *)newIncident
{
if (incident != newIncident)
{
[incident release];
incident = [newIncident retain];
}
}
注意的有差別,裏面的釋放和保留之間的訪問,如果將返回nil對象。 – Jano
是的,我想你會推薦autoreleasing對象? – mrd3650
是的,'[事件autorelease];事件= newIncident;'或'ID =事件;事件= [newIncident retain]; [舊版本];'如果你喜歡,你可以添加'if'。或者只是刪除整個事物並使用@synthesize生成的方法。生成的代碼在這裏:http://www.opensource.apple.com/source/objc4/objc4-371.2/runtime/Accessors.subproj/objc-accessors.m – Jano