ios - Why can't I have property named 'retain' when using XCode? -


in xcode 4.6.2 arc, if have property in class named 'retain', either ide or compiling stack funny, making class can't used in usual pattern: [[myclass alloc] init].

for instance, if define class foo as

// foo.h  #import <foundation/foundation.h>  @interface mosquittomessage : nsobject  @property (nonatomic, assign) bool retain;  -(id)init;  @end  // foo.m  #import "foo.h"  @implementation mosquittomessage  -(id) init {   self = [super init];   return self; }  @end 

it compile , run, however, can't use

foo *foo = [[foo alloc] init]; 

to create foo. above statement in run time set foo nil. traced problem using debugger , found alloc in fact returned valid foo, yet inside init, got deallocated reason , returned self nil.

anyone has idea 'bug' in xcode or compiling system?

added:

sure 'retain' reserved in obj-c, question why didn't compiler complain if it's not allowed? instead, generated wrong code.

retain method of nsobject.

- (id)retain; 

behind scenes, arc changing code following, before compiling.

foo *foo = [[[foo alloc] init] retain]; 

but setting bool property called retain, you've told compiler there a

- (bool)retain; 

so rather foo being assigned id returned nsobject's retain method, it's being assigned bool returned retain method. , if haven't defined method, nil that's in ivar _retain.

[edit]you didn't error because it's legal overload superclass method own replacement. not useful in case.

it doesn't seem problem such. languages have reserved words shouldn't use. 1 can think of methods of nsobject being part of reserved word list. (thought isn't reserved word of obj-c. nsobject part of apple's api, not obj-c such.)


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -