ObjectiveC数组

 // insert code here...
    NSLog(@"数组");
	//指定多个字符串创建数组
	NSArray *array;
	array=[NSArray	arrayWithObjects:@"0-asd",@"1-fds",@"2-哈咯",@"3-个人",nil];
	//数组的长度
	NSLog(@"数组长度%d",array.count);
	//通过索引取得对象
	for(int i=0;i<array.count;i++)
	{
		NSString *secondStr=[array objectAtIndex:i];
		NSLog(secondStr,nil);
	}
	//高速枚举法取得对象,Objective-C2.0开始支持,
	for(NSString *str in array)
	{
		NSLog(str,nil);
	}
	//对象的追加于删除
	//创建空数组
	NSMutableArray *MutArray=[NSMutableArray array];
	//追加对象
	[MutArray addObject:@"A"];
	[MutArray addObjectsFromArray:array];
	//插入对象
	NSString *thstr=@"插入值";
	[MutArray insertObject:thstr atIndex:4];
	//替换对象
	[MutArray replaceObjectAtIndex:2 withObject:@"替换"];
	//删除所有对象
	//[Mutarray removeAllObjects];
	//删除最后的对象
	[MutArray removeLastObject];
	//删除索引为Index的对象
	[MutArray removeObjectAtIndex:0];
	//删除所有于object同值的对象
	[MutArray removeObject:@"0-asd"];
	//删除数组中所有与object等价的对象
	[MutArray removeObjectIdenticalTo:thstr];
	//删除数组中所有与数组array包含相同的元素
	[MutArray removeObjectsInArray:array];
	NSLog(@"%@",MutArray);

  

原文地址:https://www.cnblogs.com/chu888chu888/p/2254563.html