macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

exchangeObjectAtIndex:withObjectAtIndex:

変更可能な配列の指定番号オブジェクトと別の指定番号オブジェクトを入れ替えます
-(void)exchangeObjectAtIndex:(unsigned)idx1:
           withObjectAtIndex:(unsigned)idx2:

解説

変更可能な配列の指定した番号のオブジェクト(idx1)ともう一つの指定した番号のオブジェクト(idx2)を入れ替えます。

返り値

( void )

なし

引数

( unsigned )idx1

入れ替えるオブジェクト1の番号

( unsigned )idx2

入れ替えるオブジェクト2の番号

クラス

NSMutableArray

Instance Methods

使用可能

10.2

参照

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSArray *arr1 = [NSArray arrayWithObjects:@"a", @"b",@"a", @"b",@"a", @"b",@"a", nil];


NSMutableArray *muArr = [NSMutableArray arrayWithCapacity:1];
[muArr addObjectsFromArray:arr1];
NSLog([muArr description]);
[muArr exchangeObjectAtIndex:1 withObjectAtIndex:2];
NSLog([muArr description]);
}

@end