Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSInteger,NSNumber "property 'x' with 'retain' attribute must be of object type "

Tags:

iphone

I am working an application in which data is being populated from an sqlite database. All database related stuff is done in the appdelegate class. I have used NSMutable array to hold objects. I have used a separate NSObject class for properties.

I am getting the error: property 'x' with 'retain' attribute must be of object type.

My appdelegate.m file's code is as:

NSString *amovieName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; NSInteger amovieId = sqlite3_column_int(compiledStatement, 1); //problem is here the  //value of movieId is coming from database. //But error: "must be of object type" is puzzling me.  //I am assuming to use NSNumber here. 

my NSObject file's code is as:

in .h file-

NSInteger movieId; 

its property as:

@property (nonatomic, retain) NSInteger movieId; 

and in .m file-

@synthesize movieId;  

then I have just initialize as:

-(id)initWithmovieName:(NSString *)mN movieId:(NSInteger)mId  {         self.movieName=mN;       self.movieId=mId;       return self;   } 

I found another way as: assigning value in a NSnumber object .then type caste in NSInteger.for ex;

NSNumber aNSNumbermovieID = sqlite3_column_int(compiledStatement, 1);              NSInteger amovieId = [aNSNumbermovieID integerValue]; 

but still I am getting the same errors(property 'x' with 'retain' attribute must be of object type).

Any suggestion?

like image 433
maddy Avatar asked Apr 18 '11 07:04

maddy


2 Answers

NSInteger is a scalar and not an object. So you shouldn't retain it, it should be assigned. Changing your property will clear up the warning message. You don't need to do the NSNumber stuff that you added in.

@property (nonatomic, assign) NSInteger movieId; 

It's a little confusing since NSInteger sounds like a class, but it's just a typedef for int. Apple introduced it as part of 64-bit support so that they can typedef it to the appropriately sized integer for the processor the code is being compiled for.

like image 50
McCygnus Avatar answered Sep 18 '22 18:09

McCygnus


Just use NSNumber and you can do:

@property (nonatomic, retain) NSNumber *movieId; 
like image 33
Honza Pokorny Avatar answered Sep 17 '22 18:09

Honza Pokorny