OC5


#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
#pragma mark - 数组
// 实例方法初始化
NSArray *array = [[NSArray alloc]initWithObjects:@"1",@"2",@"3", nil];
NSArray *array1 = [[NSArray alloc]initWithArray:array];
NSLog(@"array = %@ array1= %@",array,array1);
// //便利初始化方法
// NSArray *array2 = [NSArray arrayWithObjects:@"3",@"4", nil];
// NSLog(@"array2= %@",array2);
// //简化操作
// NSInteger age = 10;//数值转换
// NSArray *array3 = @[@"5",@"6",@(age)];
// NSLog(@"array3 = %@",array3);
//
// //获取数组元素个数
// NSUInteger count = array3.count;
// NSLog(@"count= %lu",(unsigned long)count);
//
// NSInteger a = [array2 count];
// NSLog(@"a= %ld",(long)a);
// 数组的运算:
// 添加元素
// NSArray *array4 = [NSArray arrayWithObjects:@"6",@"8",@"9",@"0",nil];
// NSArray *add = [array4 arrayByAddingObject:@"4"];
// NSArray *add1 = [array4 arrayByAddingObjectsFromArray:array];
// NSLog(@"add1= %@",add1);
// NSLog(@"add= %@",add);
//
// //查找元素
// NSInteger index = [add indexOfObject:@"8"];
// NSLog(@"index= %ld",(long)index);
// //获取元素
// NSString *numberString = add[0];
// NSLog(@"number= %@",numberString);
//
// NSString *numberString1 = [add objectAtIndex:1];
// NSLog(@"number= %@",numberString1);
// //获取第一个
// NSString *a = [add firstObject];
// NSString *b = add.firstObject;
// NSLog(@"a= %@",a);
// NSLog(@"b= %@",b);
// //获取最后一个
// NSString *a1 = [add lastObject];
// NSString *b1 = add.lastObject;
// NSLog(@"a1= %@",a1);
// NSLog(@"b1= %@",b1);
//
// //获取部分元素
// NSArray *number = [add subarrayWithRange:NSMakeRange(1, 2)];
// NSLog(@"number= %@",number);
// 数组的排序
// NSArray *array = @[@"12",@"5",@"7",@"3",@"9",@"4"];

// NSArray *b = [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];//比较的是字符
// NSLog(@"%@",b);

// caseInsensitiveCompare\Compare的区别:

// NSArray *a = [array sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
// NSInteger a = [obj1 integerValue];
// NSInteger b = [obj2 integerValue];
// if (a > b) {
// return 1;
// }else if(a == b){
// return 0;
// }else{
// return -1;
// }
// }];
// NSLog(@"%@",a);
#pragma mark - 数组的遍历
//普通遍历
// for (int i = 0; i < array.count; i ++) {
NSLog(@"%@",array[i]);
// NSLog(@"%@",[array objectAtIndex:i]);
// }
//快速枚举
// for (id arr in array) {
// NSLog(@"arr= %@",arr);
// }
#pragma mark - NSMutableArray
//初始化
// NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects:@"1",@"2", nil];
NSMutableArray *mutableArray1 = [NSMutableArray arrayWithObjects:@"1",@"2", nil];
// //增
// [mutableArray addObject:@"3"];//添加一个
// NSLog(@"add= %@",mutableArray);
[mutableArray addObjectsFromArray:mutableArray1];//添加数组
// //删
// [mutableArray removeObjectAtIndex:0];
// NSLog(@"remo= %@",mutableArray);
// //查
// NSInteger index = [mutableArray indexOfObject:@"2"];
// NSLog(@"index= %ld",index);
// //改(替换)
// [mutableArray replaceObjectAtIndex:0 withObject:@"000"];
// NSLog(@"repl= %@",mutableArray);
// //排序
// [mutableArray sortedArrayUsingSelector:@selector(compare:)];
// NSLog(@"sort= %@",mutableArray);
#pragma mark --iOS9 新特性
// NSArray<NSString*> *array = @[@"hello1111"];
// NSInteger lenth = array.firstObject.length;
// NSLog(@"string= %ld",lenth);

#pragma mark - 字典NSDictionary
//key - value 键值对
//初始化
// NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"one",@"1",@"two",@"2", nil];
// NSLog(@"dictionary= %@",dictionary);
//
// //字典的快速生成
// NSDictionary *newdictionary = @{@"1" : @"one",
// @"2" : @"two"
// };
// NSLog(@"dictionary= %@",newdictionary);
// //键值对的个数
// NSLog(@"count= %ld", dictionary.count);
//
// //查询一个对象
// NSString *string = dictionary[@"1"];
// NSLog(@"string= %@", string);
// NSString *string1 = [dictionary objectForKey:@"1"];
// NSLog(@"string1 = %@", string1);
// //取出所有的key
// NSArray *keys = [dictionary allKeys];
// NSLog(@"keys = %@", keys);
// //取出所有的对象
// NSArray *values =[dictionary allValues];
// NSLog(@"values = %@",values);
#pragma mark - 字典的遍历
//因为字典是以key-value形式存在,所以不可以直接遍历出一对,只能keys 或 value
//字典是无序的

//根据key,遍历所有的value

// for(int i = 0 ; i < dictionary.count; i ++){
NSString *key =[keys objectAtIndex:i];
// NSString *key =keys[i];
NSString *value = [dictionary objectForKey:key];
// NSString *value = dictionary[key];
// NSLog(@"value= %@",value);
// }
//
//
// //快速枚举:遍历字典,保存的是key
// for (id obj in dictionary) {
// NSLog(@"obj= %@",dictionary[obj]);
// }

#pragma mark - NSMutableDictionary
// NSMutableDictionary *mutableDictionary = [NSMutableDictionary
// dictionaryWithObjectsAndKeys:@"one",@"1",@"two",@"2", nil];
// //增:添加没有顺序
// [mutableDictionary setValue:@"three" forKey:@"3"];
// NSLog(@"mutableDictionary= %@",mutableDictionary);
//
// //删
// [mutableDictionary removeObjectForKey:@"3"];
// NSLog(@"mutableDictionary= %@",mutableDictionary);
//
// //查
//
// NSLog(@"a= %@",mutableDictionary [@"1"]);
// //改(根据key将原来的覆盖掉)
// //setobject...forkey方法,如果字典中没有添加的这个Key,就做添加处理,如果有,当修改处理
// [mutableDictionary setObject:@"four" forKey:@"2"];
// NSLog(@"%@",mutableDictionary);



//假设我要用字典存4个人的信息:字典数组
// NSDictionary *dic = @{@"A" : @"YES",
// @"B" : @{
// @"math":@"tom",
// @"book"
// : @[@"english",@"chinese"]
// }
// };
// NSLog(@"%@",dic[@"B"][@"book"][0]);
//
//
//#pragma mark - NSSet
// NSSet *set = [NSSet setWithObjects:@"1",@"2",@"1",@"2",@"1", nil];
// NSLog(@"%@",set);
//
//
// //取出一个
// NSLog(@"%@",[set anyObject]);
// //取所有的对象
// NSLog(@"%@",[set allObjects]);

//里面的对象不能存放重复对象,主要用于去除重复数
}
return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值