【发布时间】:2012-06-16 05:54:37
【问题描述】:
关于以下课程我有几个问题要问
#import <Cocoa/Cocoa.h>
@interface SomeObject {
NSString *title;
}
@property (retain) NSString *title;
@end
implementation SomeObject
@synthesize title;
-(id)init {
if (self=[super init])
{
self.title=[NSString stringWithFormat:@"allyouneed"];
}
return self;
}
-(void)testMethod{
self.title=[[NSString alloc] init] ;
}
-(void)dealloc {
self.title=nil;
[super dealloc];
}
- 在.h文件中添加属性时是否需要声明title和sub。添加@property (retain) NSString *title 是否不够?行。
2.我是否需要在 init 和 testMethod 中自动释放对标题的分配。如果那为什么?
谁能给我解释一下这些事情。
【问题讨论】:
-
你应该阅读Advanced Memory Management Programming Guide。您需要的一切都在里面。
-
@ChristophWinkler 我会读的。谢谢
标签: iphone objective-c ios properties