Storing and retrieving int64_t from NSDictionary: NSNumber vs NSString

I am developing a game with Game Center functionality. Inside, my game contains all evaluations in type variables int64_t, since it is a required type for reporting using the API GameKit(I assume that this should avoid ambiguity between 32-bit and 64-bit platforms).

So far so good.

Then I want to save the user box locally (say, in NSUserDefaults, but .plist would be equivalent) if there is no authenticated Game Game Player, and also synchronize it using the iCloud key value with other devices belonging to the user.

I can save int64_t hiscore as follows:

// (int64_t) _hiscore is an ivar.
// (NSString) _playerID is the authenticated player ID, or else 
//  "AnonymousUser" when GKLocalPlayer is not authenticated.

[playerData setObject:@(_hiscore) forKey:@"HiScore"];
[[NSUserDefaults standardUserDefaults] setObject:playerData forKey:_playerID];
[[NSUserDefaults standardUserDefaults] synchronize];

... ( , "@()" - ...), NSNumber ?

-*value (, -intValue, -longValue, -unsignedIntegerValue ..) , ( int64_t ). , NSNumber...

(, sizeof(unsigned long) 4 8, ), . , , ...

, , NSNumber, ...

?

+4
1

-[NSNumber longLongValue]. C (C99) long long 64 .

, @(_hiscore) [NSNumber numberWithLongLong:_hiscore], _hiscore int64_t.

+7

Source: https://habr.com/ru/post/1535553/


All Articles