Skip to content

Instantly share code, notes, and snippets.

@katsuhide
Last active December 18, 2015 00:29
Show Gist options
  • Save katsuhide/5697246 to your computer and use it in GitHub Desktop.
Save katsuhide/5697246 to your computer and use it in GitHub Desktop.
配列(NSArray, NSMutableArray)周り
// autorelease onで生成
NSMutableArray *Array = [NSMutableArray array];
// autorelease offで生成
NSMutableArray *Array = [[NSMutableArray alloc] init];
NSMutableArray *Array = [[NSMutableArray alloc] initWithObjects: nil];
// 配列の作成
NSArray *ar = [NSArray arrayWithObjects:@"東京", @"名古屋", @"大阪", nil];
// index指定で要素を取得
[array objectAtIndex:0];
// 要素を追加
NSMutableArray *array = [[NSMutableArray alloc]init];
[array addObject:@"name"];
// 指定した場所の要素を削除する
 [mar removeObjectAtIndex:3];
// 要素数をカウント
[array count]
// ソート
NSArray *array = @[@"The", @"Catcher", @"in", @"the", @"Rye"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:@[sortDescriptor]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment