【Foundation-10-4】#import <Foundation/NSArray.h>可变数组,一般

来源:互联网 发布:婚庆效果图设计软件 编辑:程序博客网 时间:2024/05/17 00:50



@interface NSMutableArray :NSArray


- (void)addObject:(id)anObject;

- (void)insertObject:(id)anObject atIndex:(NSUInteger)index;

- (void)removeLastObject;

- (void)removeObjectAtIndex:(NSUInteger)index;

- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;

- (instancetype)init NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithCapacity:(NSUInteger)numItemsNS_DESIGNATED_INITIALIZER;

- (instancetype)initWithCoder:(NSCoder *)aDecoderNS_DESIGNATED_INITIALIZER;


@end

    NSMutableArray *arr = [NSMutableArray array];//一般用这个就行了    NSMutableArray *arr2 = [[NSMutableArray alloc]initWithCapacity:0];//数组大小//    NSMutableArray *arr3 = [NSMutableArray alloc]initWithCoder:@""];            [arr addObject:@"1"];    [arr addObject:@"2"];    [arr addObject:@"3"];        [arr insertObject:@"4" atIndex:1];        [arr removeLastObject];        [arr removeObjectAtIndex:0];        [arr replaceObjectAtIndex:0 withObject:@"??"];                NSLog(@"%@",arr);    



@interface NSMutableArray (NSMutableArrayCreation)


+ (instancetype)arrayWithCapacity:(NSUInteger)numItems;


+ (NSMutableArray *)arrayWithContentsOfFile:(NSString *)path;

+ (NSMutableArray *)arrayWithContentsOfURL:(NSURL *)url;

- (NSMutableArray *)initWithContentsOfFile:(NSString *)path;

- (NSMutableArray *)initWithContentsOfURL:(NSURL *)url;

    NSString *path = [[NSBundle mainBundle]pathForResource:@"testArray" ofType:@"plist"];    NSMutableArray *arr0 = [NSMutableArray arrayWithCapacity:0];        arr0 = [NSMutableArray arrayWithContentsOfFile:path];   // 类方法//    arr0 = [[NSMutableArray alloc]initWithContentsOfFile:path];   //实例方法        NSLog(@"%@",arr0);    
获取URL 类似

@end



0 0