objective-c – 如何在Cocoa中将NSString转换为unsigned int?

前端之家收集整理的这篇文章主要介绍了objective-c – 如何在Cocoa中将NSString转换为unsigned int?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序获得了一个包含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];

谢谢你尽你所能的帮助!

猜你在找的C&C++相关文章