NSNumber的常用方法
在Objective-c中有int的數據類型,那為什么還要使用數字對象NSNumber?這是因為很多類(如NSArray)都要求使用對象,而int不是對象。
NSNumber就是數字對象我們可以使用NSNumber對象來創建和初始化不同類型的數字對象。
NSNumber
+ (NSNumber *)numberWithInt:(int)value;
+ (NSNumber *)numberWithDouble:(double)value;
- (int)intValue;
- (double)doubleValue;
.....................(對于每個基本類型,類方法都為這它分配了一個NSNumber對象,并將其設置為指定的值,這些方法都是以numberWith開始的,之后是類型,如numberWithFloat,numberWithLong,numberWithInteger.....)
包裝后取出來的方法如下:
下面就拿int做個demo:
NSDictionary一些常用用法
//刪除指定鍵值的數據
[mutableDictionary removeObjectForKey:..];
//刪除所有數據
[mutableDictionary removeAllObjects];
//字典的普通遍歷(無序)
for (int i =0; i < [yourDic count]; i++) {
NSLog(@"key = value <====> %@ = %@",[[yourDic allKeys] objectAtIndex:i],[yourDic objectForKey:[[yourDic allKeys]objectAtIndex:i]]);
}
// 字典的快速遍歷 取出來的obj一定是key
for (id obj in yourDic) {
NSLog(@"%@",obj);
id value = [yourDic objectForKey:obj];
NSLog(@"%@",value);
}
新聞熱點
疑難解答