Autorelease and properties
Posted
by
ganuke
on Stack Overflow
See other posts from Stack Overflow
or by ganuke
Published on 2012-06-13T09:36:12Z
Indexed on
2012/06/13
10:40 UTC
Read the original article
Hit count: 197
I have few questions to ask about the following class
#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];
}
- In the .h file do we need to declare the title and sub when we add the property. is it not enough to add the @property (retain) NSString *title; line.
2.Do i need to autorelease both assignment to title in the init and testMethod. if So why?
Can some one explain these things to me.
© Stack Overflow or respective owner