OC可变数组的创建与简单应用

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    //NSMutableArray * array1 = [[NSMutableArray alloc]initWithObjects:@"one",@"two",@"three", nil];
    NSArray * array = @[@"1",@"2",@"3"];
    //用不可变数组初始化一个可变数组
    
    NSMutableArray * array2 = [[NSMutableArray alloc]initWithArray:array];
    
    //2.指定对象插入位置
    //index 要小于count
    NSString * str1 = @"one";
    [array2 insertObject:str1 atIndex:2];
    NSLog(@"%@",array2);
    //3.删除 会通过对象地址 删除数组中同一个元素的对象
    [array2 addObject:str1];
    NSLog(@"%@",array2);
    
    //删除全部对象
    [array2 removeAllObjects];
    NSString * str4 = @"4";
    [array2 addObject:str4];
    NSLog(@"%@",array2);
    
    //    for(NSString * str in array2)
    //    {
    //        [array2 removeObjectAtIndex:0];
    //    }
    //
    
    
    return 0;
}

你可能感兴趣的:(数组,对象,Objective-C,ios开发,Foundation框架)