4

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

当尝试使用 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包含以下数字(= Tweet Id):

491621469123018752,
491621468917477377,
491621465544851456,
491621445655867393

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

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

4

1 回答 1

4

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

uint64_t minID = [Ids.lastObject longLongValue];

编辑

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

于 2014-07-28T12:48:59.243 回答