我的应用程序获得了一个包含unsigned int的NSString. NSString没有[myString unsignedIntegerValue];方法.我希望能够从字符串中取出值而不对其进行修改,然后将其放在NSNumber中.我试着这样做:
NSString *myUnsignedIntString = [self someMethodReturningAString]; NSInteger myInteger = [myUnsignedIntString integerValue]; NSNumber *myNSNumber = [NSNumber numberWithInteger:myInteger]; // ...put |myNumber| in an NSDictionary,time passes,pull it out later on... unsigned int myUnsignedInt = [myNSNumber unsignedIntValue];
以上是否可能会“切断”大型unsigned int的结尾,因为我必须首先将其转换为NSInteger?或者看起来可以使用吗?如果它会切断它的结尾,下面怎么样(我认为有点像kludge)?
NSString *myUnsignedIntString = [self someMethodReturningAString]; long long myLongLong = [myUnsignedIntString longLongValue]; NSNumber *myNSNumber = [NSNumber numberWithLongLong:myLongLong]; // ...put |myNumber| in an NSDictionary,pull it out later on... unsigned int myUnsignedInt = [myNSNumber unsignedIntValue];
谢谢你尽你所能的帮助! 原文链接:https://www.f2er.com/c/118038.html