NSMutableArray的函数图
2013-04-30 13:54 甘超波 阅读(4722) 评论(0) 编辑 收藏 举报个人乱猜的:由于API函数较多,一般增加开头 Insert Add,Append,set开头
删除 :remove deleted
替换; repace
查询 sort
// // main.m // RunTime // // Created by ganchaobo on 13-4-29. // Copyright (c) 2013年 ganchaobo. All rights reserved. // #import <Foundation/Foundation.h> void NSArrayAdd(){//add insert set; //初始化数组 NSMutableArray *MutableArray=[NSMutableArray arrayWithObjects:@"1",@"2", nil]; //为数组添加一个对象 [MutableArray addObject:@"3"];// //NSLog(@"%@",MutableArray); //初始化数组 NSMutableArray *MutableArray1=[NSMutableArray arrayWithObjects:@"1",@"2", nil]; NSArray *arr=[NSArray arrayWithObjects:@"AB",@"FV", nil]; //让数组中添加数组 //[MutableArray addObjectsFromArray:arr]; //在指定位置中插入对象 //[MutableArray insertObject:@"av" atIndex:2]; NSMutableIndexSet *set=[NSMutableIndexSet indexSet]; [ set addIndex:1]; [set addIndex:0]; [MutableArray insertObjects:arr atIndexes:set]; NSArray *arr2=[NSArray arrayWithObjects:@"11", nil]; [MutableArray setArray:arr2]; NSLog(@"%@",MutableArray); } void ArrayRemove(){//remove delete NSMutableArray *arr=[NSMutableArray arrayWithObjects:@"AB",@"FV",@"dd",@"AB", nil]; // [arr removeObject:@"AB" inRange:NSMakeRange([arr count]-2, 2)]; //[arr removeObjectAtIndex:1]; // NSMutableIndexSet *set=[NSMutableIndexSet indexSet]; // [set addIndex:1]; // [set addIndex:3]; // [arr removeObjectsAtIndexes:set]; NSArray *AR=[NSArray arrayWithObjects:@"AB",@"12", nil]; [arr removeObjectsInArray:AR];//移除指定数组中相同d的元素 NSLog(@"%@",arr); } void NSArrayRelace(){ NSMutableArray *arr=[NSMutableArray arrayWithObjects:@"AB",@"FV",@"dd",@"AB", nil]; //[arr replaceObjectAtIndex:2 withObject:@"cc"]; // NSArray *arr1=[NSArray arrayWithObjects:@"1",@"2", nil]; // NSMutableIndexSet *index=[NSMutableIndexSet indexSet]; // [index addIndex:2]; // [index addIndex:0]; // [arr replaceObjectsAtIndexes:index withObjects:arr1]; //NSArray *A= [NSArray arrayWithObjects:@"V",@"T",@"B" nil]; NSArray *A=[NSArray arrayWithObjects:@"v",@"T",@"B", nil]; // [arr replaceObjectsInRange:NSMakeRange([arr count]-2, 2) withObjectsFromArray:A]; // [arr replaceObjectsInRange:NSMakeRange([arr count]-2, 2) withObjectsFromArray:A range:NSMakeRange([A count]-2, 2)]; NSLog(@"%@",arr); } void NSArraySort(){ NSMutableArray *arr=[NSMutableArray arrayWithObjects:@"1",@"2",@"5",@"3", nil]; [arr sortUsingSelector:@selector(compare:)]; NSLog(@"%@",arr); } int main(int argc, const char * argv[]) { @autoreleasepool { NSArraySort(); } return 0; }
目前我正在专注NLP,请立刻加微信/QQ号 546611623, 免费送你原创《NLP高级执行师》高清视频