Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coding standard for parsing primitive types in iOS

What is the best practice for parsing primitive type in iOS (int, float, BOOL etc.) while storing them in dataObjects for later use.

Should i parse it and store it as a NSNumber, or just store it as a primitive type property?

For example: if i'm getting 'userId' from server as long type. Should this be:

@property (nonatomic, strong) NSNumber *userId;

self.userId = [element objectForKey:@"user_id"];

or:

@property (nonatomic, assign) long userId;

self.userId = [[element objectForKey:@"user_id"] longValue];

Thanks.

like image 895
Lirik Avatar asked Nov 10 '22 16:11

Lirik


1 Answers

In my view, it's a good practice to have it in primitive form as long as you will not indulge them in heavy operations. It's one less burden for the compiler. Of course, it doesn't even cost a clock-cycle for the processor. But, it gets efficient as you move on to bigger number of data.

like image 99
Srikanth R Avatar answered Nov 13 '22 08:11

Srikanth R