在32位iPhone上处理64位整数

时间:2014-07-28 12:43:02

标签: ios objective-c arm nsuinteger

我想在iPhone 4s上处理 64位无符号整数(当然它有32位ARM 6处理器)。

尝试使用64位无符号整数时,例如Twitter ID,我有以下问题:

// Array holding the 64 bit integer IDs of the Tweets in a timeline:
NSArray *Ids =[timelineData valueForKeyPath:@"id"];

// I would like to get the minimum of these IDs:
NSUInteger minId = (NSUInteger) Ids.lastObject;

数组Ids包含以下数字(=推文ID):

491621469123018752,
491621468917477377,
491621465544851456,
491621445655867393

但是,minId返回的值不正确399999248(而不是491621445655867393

如何在iPhone 4s上找到64位整数数组中的最小或最后一个对象?

1 个答案:

答案 0 :(得分:4)

您需要使用始终为64位而不是NSUInteger的类型。您可以使用uint64_tunsigned long long。您还需要从NSNumber中获取整数值(数组不能存储C类型)。为此,您需要致电

uint64_t minID = [Ids.lastObject longLongValue];

修改

更改为在示例代码中使用uint64_t,因为它已被正确指出,这更好地显示了您的意图。