addObject:
変更可能な配列の末尾にオブジェクトを加えます
-(void)addObject:(id)anObject
解説
変更可能な配列の末尾にオブジェクトを加えます。
オブジェクトは、配列に追加される前にretainメッセージを送信されます。
追加するオブジェクトがnilならNSInvalidArgumentExceptionが起こされます。
返り値
( void )
なし
引数
( id )anObject
追加するオブジェクト
フレームワーク
Foundation
クラス
NSMutableArray
Instance Methods
使用可能
10.0
iOS 2.0
参照
- addObjectsFromArray:
- removeObject:
- setArray:
例文
#pragma mark addObject: -(void)method002 { NSMutableArray *anArray = [[NSMutableArray alloc] initWithCapacity:0]; [anArray addObject:@"aaa"]; [anArray addObject:[NSNumber numberWithFloat:2.0]]; [anArray addObject:@"bbb"]; [anArray addObject:@"ccc"]; NSLog(@"%s : %@", __FUNCTION__,[anArray description]); //=>[OOOAppDelegate method001] : (aaa,2,bbb,ccc) [anArray addObject:@"+++"]; NSLog(@"%s : %@", __FUNCTION__,[anArray description]); //=>[OOOAppDelegate method001] : (aaa,2,bbb,ccc,"+++") [anArray removeObjectAtIndex:2]; NSLog(@"%s : %@", __FUNCTION__,[anArray description]); //=>[OOOAppDelegate method001] : (aaa,2,ccc,"+++") }