OC基礎語法

//? ? ? ? 數(shù)組(NSArray/NSMutableArray)

//? ? ? ? 不可變數(shù)組

NSArray *array1 = @[@"a",@"b",@"c",@"d"];

//創(chuàng)建

NSLog(@"array1 = %@",array1);

//? ? ? ? 數(shù)組元素個數(shù).count

NSLog(@"count = %ld",array1.count);

//? ? ? ? 通過下標訪問數(shù)組里面的元素

NSString *str = array1[0];

NSLog(@"str = %@",str);

//? ? ? ? 可變數(shù)組NSMutableArray

NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];

NSLog(@"mutableArray = %@",mutableArray);

//? ? ? ? 元素個數(shù):count

NSLog(@"count = %ld",mutableArray.count);

//? ? ? ? 添加個數(shù)

[mutableArray addObject:@"5"];

NSLog(@"已添加----%@",mutableArray);

//? ? ? ? 移除元素

[mutableArray removeObject:@"3"];

NSLog(@"已移除----%@",mutableArray);

//? ? ? 字典(存放多個鍵值對(key-value)的一種數(shù)據(jù)類型)

//? ? ? ? (NSDictionary,NAMutableDictionary)

//? ? ? ? 不可變字典NSDictionary

NSDictionary *dict = @{@"key1":@"value1",@"key2":@"value2",@"key3":@"value3"};

NSLog(@"dict = %@",dict);

NSString *string = [dict objectForKey:@"key1"];

NSLog(@"string = %@",string);

//? ? ? ? 所有的key值,所有的value值

NSLog(@"allkeys = %@,@allvalues = %@",dict.allKeys,dict.allValues);

}

return 0;

}

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容