//
// main.m
// NSMutableArray的基本使用
//
// Created by apple on 15/9/18.
// Copyright (c) 2015年 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// NSMutableArray 是一个可变长度数组
// 1,创建
// 2,新增数据
// -(void)addObject:(id)anObject;
// -(void)insertObject:(id)anObject atIndex:(NSUInteger)index;
// 3,删除数据
// -(void)removeLastObject;
// -(void)removeObjectAtIndex:(NSUInteger)index;
// -(void)removeObject:(id)anObject;
// 4,修改数据
// -(void)replaceObjectAtIndex:(NSUInteger)index withObject withObject:(id)anObject;
// 5,交换元素
// -(void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUIteger)idx2;
//定义一个可变数组
NSMutableArray *arr = [NSMutableArray array];
//新增追加
[arr addObject:@"1"];
[arr addObject:@"2"];
// 插入
[arr insertObject:@"a" atIndex:1];
NSLog(@"%@",arr);
//删除
[arr removeObject:@"a"];
NSLog(@"%@",arr);
//修改
[arr replaceObjectAtIndex:1 withObject:@"壹"];
NSLog(@"%@",arr[1] );
}
return 0;
}