Question

I am using JSONModle, but i meet a problem, i am not sure how can i handle it?

@interface MessageModel : JSONModel

@property(nonatomic, strong) NSString*           create_at;
@property(nonatomic, assign) long                message_id;
@property(nonatomic, assign) int                 message_type;    
@property(nonatomic, strong) NSString<Optional>* text;
@property(nonatomic, assign) int<Optional>       background_no;   
@end

About property background_no, it's type is int, can i use Optional? If not, how can i do?

Was it helpful?

Solution

You can only apply protocols to Objective-C objects, not to primitive types. You will therefore need to use NSNumber to store the int:

@property(nonatomic) NSNumber<Optional> *background_no;

and use auto-boxing, to store it:

someObject.background_no = @(123);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top