I wonder if someone can clarify some things for me, which suddenly seem unclear.
Firstly, a snippet of some code. ( yes..it's from Kochan )
1) Why does the compiler complain if one omits the attributes of NSString * property , but not if one omits it if , for example, it is a simple integer, say "int i" as an ivar? (If I omit the attributes , I get a warning that Xcode is applying the default ( retain) attribute, and then a second warning saying that default is inappropriate for a non-gc(garbage colletion) property name). Sorry if this sounds dumb, but it usually means I am missing something quite fundmental here.
2) Specifically about the line "self.bookName = nameOfBook;". My aim is **trying** to use the synthesized accessor method. What would happen if I omitted the "self" as in "bookName = nameOfBook". (Self, in the past has been redundant...but what I want to avoid is obviously doing a direct assign and bypassing using the synthesized accessors). Will the synthesized accessor method by default initially free the objects memory before creating the new object, or is this one of the directives one supplies with the attributes.
Any other dumb thing that I am missing?
Thank you as usual in advance.
Firstly, a snippet of some code. ( yes..it's from Kochan )
Code:
/*interface*/
@interface AddressBook : NSObject {
NSString *bookName;
NSMutableArray *book;
}
@property (copy, nonatomic) NSString * bookName;
/*implementation*/
@synthesize bookName;
-(AddressBook*) initWithName: (NSString *) nameOfBook
{
self = [super init];
if ( self)
{
self.bookName = nameOfBook;
book = [NSMutableArray arrayWithCapacity: 20];
return self;
}
1) Why does the compiler complain if one omits the attributes of NSString * property , but not if one omits it if , for example, it is a simple integer, say "int i" as an ivar? (If I omit the attributes , I get a warning that Xcode is applying the default ( retain) attribute, and then a second warning saying that default is inappropriate for a non-gc(garbage colletion) property name). Sorry if this sounds dumb, but it usually means I am missing something quite fundmental here.
2) Specifically about the line "self.bookName = nameOfBook;". My aim is **trying** to use the synthesized accessor method. What would happen if I omitted the "self" as in "bookName = nameOfBook". (Self, in the past has been redundant...but what I want to avoid is obviously doing a direct assign and bypassing using the synthesized accessors). Will the synthesized accessor method by default initially free the objects memory before creating the new object, or is this one of the directives one supplies with the attributes.
Any other dumb thing that I am missing?
Thank you as usual in advance.