#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; /*可變數組*/ NSMutableArray *aMutableArray = [NSMutableArray arrayWithCapacity:5]; //初始化對象方法 //插入元素 [aMutableArray addObject:@"firstobject"]; [aMutableArray addObject:@"secondobject"]; NSLog (@"aMutableArray = %@",aMutableArray); //指定位置插入元素 [aMutableArray insertObject:@"andrlee" atIndex:1]; NSLog (@"aMutableArray = %@",aMutableArray); //刪除元素 [aMutableArray removeObject:@"andrlee"]; NSLog (@"aMutableArray = %@",aMutableArray); //刪除指定位置元素 [aMutableArray removeObjectAtIndex:1]; NSLog (@"aMutableArray = %@",aMutableArray); //遍歷 for(NSString *value in aMutableArray) { NSLog (@"value = %@",value); } //固定長度數組 NSArray *aImmutableArray = [[NSArray alloc] initWithObjects:@"firstObject",nil]; NSLog (@"aImmutableArray = %@",aImmutableArray); [pool drain]; return 0; }