Create getter / setter int?

@property (retain) int myInteger;

This causes an error because it intdoes not seem to be considered an object ... but I want to get the advantage of creating a getter / setter method with a tag @synthetize, but with int. How could I achieve this? Is there an equivalent?

+5
source share
2 answers
@property (assign) int chunkID;

or

@property (readonly) int chunkID;

You cannot save a primitive type of integer type. Only objects can be saved ...

+25
source

Use this:

@property (nonatomic, assign) int chunkID;

assign by default, so you can opt out of it.

You need to use a type property assignbecause you are dealing with a primitive type of an object (i.e. int). This type type cannot be saved.

Only subclasses of NSObject can be saved / released.

+9

All Articles