###文字列操作
// 結合
NSMutableString * string = [NSMutableString stringWithString:@"aaa"];
NSString *joined = [string appendString:@"bbb"];
// 配列を結合
NSArray *array = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSString *joined = [array componentsJoinedByString:@","];
//配列に分割
NSString * string = [NSMutableString stringWithString:@"aaa,bbb,ccc"];
NSArray *record = [string componentsSeparatedByString:@","];
// 長さ
int length = [@"abcdef" length];
//切り出し
NSString *string = [@"abcd" substringWithRange:NSMakeRange(0, 2)];
//検索
NSString *string = @"abcd";
NSRange range = [string rangeOfString:@"cd"];
NSLog(@"%d:%d", range.location, range.length);
###配列
// 作成
NSArray* array = [NSArray arrayWithObject:string];
NSArray* array = [NSArray arrayWithObjects:@"A", @"B", @"C", nil];
// 取得
NSString* thirdObj = [array objectAtIndex:2];
for (NSString* string in array) {
NSLog(string);
}
// 追加
NSMutableArray* array = [NSMutableArray array];
[array addObject:@"A"];
NSArray* arrayB = [NSArray arrayWithObjects:@"B", @"C", @"D", nil];
[array addObjectsFromArray:arrayB];
// 挿入
[array insertObjects:@"E" atIndex:0];
// 置換
[array replaceObjectAtIndex:1 withObject:@"F"];
###辞書
// 作成
NSDictionary* dic = [NSDictionaryWithObject:@"Taro" forKey:@"name"];
// 追加
NSDictionary * dic = [NSDictionary dictionary];
[dic setObject:obj ForKey:@"key"];
// 取得
NSString* str = [dic objectForKey:@"key"];
for (id key in dic) {
NSLog(@"key: %@, value: %@\n", key, [dic objectForKey:key]);
}
###例外処理
@try {
// something
}
@catch (NSException *e) {
NSLog(@"Error: %@: %@", [e name], [e reason]);
}
@finally {
// something
}
NSException *exception = [NSException exceptionWithName:@"hoge" reason:@"foo" userInfo:nil];
@throw exception;