Person *person1=[[Person alloc]initWithName:@"Kenshin"];
Person *person2=[[Person alloc]initWithName:@"Kaoru"];
Person *person3=[[Person alloc]initWithName:@"Rosa"];
NSMutableArray *array1=[NSMutableArray arrayWithObjects:
person1,
person2,
person3,
nil
];
//NSLog(@"%@",array1);
/*结果:
(
"name=Kenshin",
"name=Kaoru",
"name=Rosa" )
*/
Person *person4=[[Person alloc]initWithName:@"Jack"];//此时person4的retainCount为1
[array1 addObject:person4];//添加一个元素,此时person4的retainCount为2
//NSLog(@"%@",array1);
/*结果:
(
"name=Kenshin",
"name=Kaoru", "name=Rosa", "name=Jack"
) */
[array1 removeObject:person3];//删除一个元素 NSLog(@"%@",array1);
/*结果:
(
"name=Kenshin",
"name=Kaoru",
"name=Jack" )
*/
//NSLog(@"%@",array1);
[array1 removeLastObject];//删除最后一个元素,//此时person4的retainCount为1 NSLog(@"%@",array1);
/*结果:
(
"name=Kenshin",
"name=Kaoru" )
*/
NSLog(@"%@",array1);
[array1 removeAllObjects];//删除所以元素
NSLog(@"%@",array1);