Iphone unsignedIntValue vs intValue

Iphone unsignedIntValue vs intValue,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,考虑下面的代码 id j = @"123"; NSUInteger a = [j unsignedIntValue]; // not working NSUInteger b = [j intValue]; // works 为什么将NSString的对象转换为无符号整数时,只有intValue起作用?这是因为unsignedIntValue是NSNumber的一种方法,而intValue同时存在于NSNumber和NSStringunsignedIntValue是类NSNumber的方法,而

考虑下面的代码

id j = @"123";
NSUInteger a = [j unsignedIntValue]; // not working
NSUInteger b = [j intValue]; // works

为什么将NSString的对象转换为无符号整数时,只有
intValue
起作用?

这是因为
unsignedIntValue
NSNumber
的一种方法,而
intValue
同时存在于
NSNumber
NSString
unsignedIntValue
是类
NSNumber
的方法,而不是
NSString

因此,当您对
NSString
的对象调用
unsigneditvalue
时,它将无法链接您的对象和函数调用