I want to use an integer variable from multiple threads.
Hence I want to make getter/setter atomic operation.at header file
@property (retain) NSNumber* myNumber;
at implementation file
@synthesize myNumber;
won't compile, what am i missing?
(type of property ‘myNumber’ does not match type of ivar ‘myNumber’) - edit, I declared it as int myNumber; compilation problem solved开发者_如何学运维Also, can I use plain int for this? (not NSNumber* )
In general, you may use int
instead of NSNumber
. Type choice depends on the problem you are trying to solve.
The particular error message you get says that your instance variable has a different type than the property with the same name. Do you clare your ivar as int myNumber
? In this case you should write
@property int myNumber;
Update
Since properties are atomic by default, you do not need to explicitly write:
@property (atomic) int myNumber;
@property (assign) int myNumber;
Add in @interface
NSNumber *myNumber;
Check your instance variable type.
Something like this in your header file:
@interface Foo : NSObject {
NSNumber *myNumber;
}
@property (retain) NSNumber *myNumber;
Use this,
@property (atomic , retain) NSNumber* myNumber;
Or use thislink text it may be helpful
精彩评论