NSUInteger和NSInteger和int
生活随笔
收集整理的這篇文章主要介紹了
NSUInteger和NSInteger和int
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
int和NSInteger其實是差不多的,但更推薦使用NSInteger,因為使用NSInteger,這樣就不用考慮設(shè)備是32位還是64位了。
NSUInteger是無符號的,即沒有負(fù)數(shù),NSInteger是有符號的,所以NSUInteger類型不能給它賦負(fù)值。比如以下這段代碼,a=-1的時候,是能進入循環(huán)的。
NSUInteger a = -1; for(int i=0;i<a;i++){ NSLog(@"%d,%lu",i,(unsigned long)a); break; } 輸出:0,18446744073709551615 這時a的值其實等于18446744073709551615還有NSUInteger和NSInteger和int都是基礎(chǔ)類型,是不能放入NSArray中的,需要轉(zhuǎn)換成NSNumber,應(yīng)為NSNumber是類,NSArray中只能放入類。
用以下NSNumber的類方法轉(zhuǎn)即可
- (NSNumber *) numberWithChar: (char) value;
- (NSNumber *) numberWithInt: (int) value;
- (NSNumber *) numberWithFloat: (float) value;
- (NSNumber *) numberWithBool: (BOOL) value;
原文鏈接:http://www.jianshu.com/p/c883674b6de5
著作權(quán)歸作者所有,轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),并標(biāo)注“簡書作者”。
轉(zhuǎn)載于:https://www.cnblogs.com/Free-Thinker/p/5868289.html
總結(jié)
以上是生活随笔為你收集整理的NSUInteger和NSInteger和int的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 统计字符串中某个字出现的次数
- 下一篇: Linq中string转int的方法