如何从 Objective C 中的 intValue 中已经超过的 MaxValue(2147483647) 中获取原始 Long 值
How to get Original Long values from already exceeded MaxValue(2147483647) in intValue in Objective C
在我的 iOS 应用程序中,我们使用下面的代码行来获取对象的 ID 值
NSNumber * newObjID = @([responceData[@"id"] intValue]);
现在的问题是,从服务器获取的“id”超出了MAX_INT_VALUE (2147483647)
所以现在进入 newObjID 的值是一些有线负值,例如
-2138406908 但应该是 2156560388
我们通过将上面的行更改为下面的 longLongValue instead of intValue
来解决这个问题
NSNumber * newObjID = @([responceData[@"id"] longLongValue]);
已保存的记录、
仍然存在问题
现在我们需要将已经错误保存的值ID更改为实际ID
是否有任何更改可以将错误的负值转换为实际长值
就像我想打印 newObjID = 2156560388 如果 newObjID = -2138406908
请帮忙
使用unsigned int
.
这个
int i = -2138406908;
unsigned int j = 2156560388;
if ( i == j )
{
NSLog(@"Same");
}
将打印 Same
。所以我觉得应该可以,只是格式化的问题。也许你需要这样做
int oldId = -2138406908; // Your old negative ID goes here
long newId = ( unsigned int ) oldId; // Note the conversion through unsigned int
NSNumber * newIdNumber = @(newId); // This is to make it a NSNumber
NSLog(@"New ID is %lu or %@", newId, newIdNumber ); // Prints OK
在我的 iOS 应用程序中,我们使用下面的代码行来获取对象的 ID 值
NSNumber * newObjID = @([responceData[@"id"] intValue]);
现在的问题是,从服务器获取的“id”超出了MAX_INT_VALUE (2147483647)
所以现在进入 newObjID 的值是一些有线负值,例如
-2138406908 但应该是 2156560388
我们通过将上面的行更改为下面的 longLongValue instead of intValue
NSNumber * newObjID = @([responceData[@"id"] longLongValue]);
已保存的记录、
仍然存在问题现在我们需要将已经错误保存的值ID更改为实际ID
是否有任何更改可以将错误的负值转换为实际长值
就像我想打印 newObjID = 2156560388 如果 newObjID = -2138406908
请帮忙
使用unsigned int
.
这个
int i = -2138406908;
unsigned int j = 2156560388;
if ( i == j )
{
NSLog(@"Same");
}
将打印 Same
。所以我觉得应该可以,只是格式化的问题。也许你需要这样做
int oldId = -2138406908; // Your old negative ID goes here
long newId = ( unsigned int ) oldId; // Note the conversion through unsigned int
NSNumber * newIdNumber = @(newId); // This is to make it a NSNumber
NSLog(@"New ID is %lu or %@", newId, newIdNumber ); // Prints OK