您的位置:首页 > 其它

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

2015-10-12 19:34 489 查看
@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)numItems
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)aDecoder
NS_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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: