如何在 Objective-C 中将 int64_t 转换为 NSInteger?
此方法返回 score 一个 int64_t*,我需要将其转换为 NSInteger:
[OFHighScoreService getPreviousHighScoreLocal:score forLeaderboard:leaderboardId];
谢谢。
最佳答案
它们应该在 64 位机器上直接兼容(或者如果您使用 NS_BUILD_32_LIKE_64
构建):
NSInteger i = *score;
documentation表示 NSInteger
的定义如下所示:
#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif
因此,在 32 位计算机上,您可能需要处理一些截断问题。在我这里的机器上,这条语句:
NSLog(@"%d %d", sizeof(int64_t), sizeof(NSInteger));
给出这个输出:
2010-03-19 12:30:18.161 app[30675:a0f] 8 8
关于objective-c - 将 int64_t 转换为 NSInteger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2480029/