objective-c - 将 int64_t 转换为 NSInteger

标签 objective-c casting nsinteger

如何在 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/

相关文章:

iphone - 如果键以 @ 符号开头,则在 NSDictionary 上使用 valueForKeyPath?

objective-c - 使用 UIControl(特别是 UIButton)时如何对目标进行排序?

c# - 类型转换/类型转换性能

objective-c - CLI 和 GUI 之间的 NSInteger 区别?

ios - 需要解释 iOS 中的@property/@synthesize

ios - 如何在单击按钮时获取 UIImageView 的高度、宽度、X 和 Y 并将其传递给其他 ViewController?

c# - 无法将类型 'byte' 转换为 'T'

C::在函数中转换指针会丢失数据吗?

ios - 单击添加错误数字的按钮向变量添加 +1

ios - 如何将 NSInteger 转换为 NSString 数据类型?