Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the getter/setter of an int?

Tags:

objective-c

@property (retain) int myInteger;

That throws me an error because apparently int is not considered an object... but I want to get the advantage of creating a getter/setter method with the @synthetize thing, but with an int. How could I achieve so? Is there an equivalent?

like image 707
Voldemort Avatar asked Mar 22 '11 23:03

Voldemort


2 Answers

@property (assign) int chunkID;

or

@property (readonly) int chunkID;

You cannot retain a primitive type like integers. Only objects can be retained...

like image 115
Macmade Avatar answered Oct 04 '22 02:10

Macmade


Use this:

@property (nonatomic, assign) int chunkID;

assign is the default so you might want to leave it out.

You need to use the assign type of property because you are dealing with a primitive object type (i.e. int). This kind of type can't be retained.

Only subclasses of NSObject can be retained / released.

like image 45
Sylvain Avatar answered Oct 04 '22 01:10

Sylvain