Code? – Design?

1211月/11Off

Objective-CでNSArray配列の順番を逆にする

チャオ!

NSArrayで中身の順番を逆にしたい場合は以下でOKOKです!

NSArray *reverseAr = [[元配列 reverseObjectEnumerator] allObjects];

 

こんな感じで使います。

NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];
NSArray *reverseAr = [[array reverseObjectEnumerator] allObjects];

NSLog(@"%@\n%@", array, reverseAr);
array
(
    1,
    2,
    3,
    4
)
reverseAr
(
    4,
    3,
    2,
    1
)

 

以上!


Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.