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
时,它将无法链接您的对象和函数调用