// main.m // OC基本语法2 // // Created by lanou on 16/7/9. // Copyright © 2016年 lanou. All rights reserved. // 数组(不可变数组 NSArray 动态数组 NSMutableArray) // #import int main(int argc, const char * argv[]) { @autoreleasepool { // // insert code here... // NSLog(@"Hello, World!"); // 数组(NSArray/ NSMutableArray) //不可变数组 NSArray *array1=@[@"a",@"b",@"c",@"d"]; //创建不可变数组 NSLog(@"array1=%@",array1); //数组元素个数 NSLog(@" count= %ld",array1.count); //通过下标访问数组里的元素 NSString *str =array1[0]; NSLog(@"str = %@",array1[0]); //可变数组NSMutableArray NSMutableArray *muteable=[NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4", nil/* 空*/] ; //创建可变数组 NSLog(@"muteable=%@",muteable); NSLog(@"count = %ld",muteable.count); //添加元素个数 [muteable addObject/*添加元素*/:@"5"]; NSLog(@"已添加的-----%@",muteable); //移除元素 [muteable removeObject/*移除元素*/:@"3"]; //元素个数:count NSLog(@"muteable已移除-----%@",muteable); //字典(存放多个键值对得一种数据结构)(NSDictionary,NSMutableDictionary)//不可变字典 NSDictionary *dict =@{ @"key1":@"value1",@"key2":@"value2",@"key3":@"value3",@"key4":@"value4"};//字典的创建 NSLog(@"dict=%@",dict); NSString *string1=[dict objectForKey:@"key1"/*通过key值找到value值*/]; NSLog(@"string1=%@",string1); //所有key值,所有value值 NSLog(@"allkey=%@,allvalue=%@",dict.allKeys,dict.allValues); //打印所有的key值遇value值
网友评论