PGzxc的博客

纸上得来终觉浅 绝知此事要躬行

0%

OC开发之——NSMutableArray(56)

一 概述

NSMutableArray与NSArray的区别:

  • NSMutableArray:可变数组
  • NSArray:不可变数组

二 示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#import <Foundation/Foundation.h>
#import "Person.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...

//数组创建
NSMutableArray *array=[NSMutableArray array];//空数组
NSMutableArray *array2=[NSMutableArray arrayWithObjects:@"rose",@"jack",@"marry",nil];
[array addObject:[[Person alloc]init]];
[array addObject:@"jack"];


//数组的操作
array.count;
[array2 removeObject:@"rose"];
//[array2 removeAllObjects];
[array2 removeObjectAtIndex:1];
NSLog(@"%ld",array.count);
NSLog(@"数组%@",array2);

}
return 0;
}