// NSDataオブジェクトへ変換(エンコード) NSData *data = [NSKeyedArchiver archivedDataWithRootObject:obj]; // 変換前のオブジェクトに復元(デコード) NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data]; こんな感じでNSData、NSArray両方の変換が出来ます。 分からなくてエラーがいっぱい出て大変でした。。。
iOS/iPhone/iPad/MacOSX プログラミング, Objective-C, Cocoaなど ISO 8601日付文字列を NSDateに変換する 例えば 2010-12-01T21:35:43+0900という文字列があった場合 NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate* date = [formatter dateFromString:string]; [formatter release];で NSDate へ変換できる。 ISO 8601 には多くのバリエーションがあって上記書式は Facebook API などで使われている ISO 8601 書式の一つ。 参考:ISO 8
文字列→日付、日付→文字列の変換を行うNSDateFormatter、理解するまではちょっと難しそうな印象があるこのクラスの使い方を解説します。 フォーマットの指定 文字列 intputDateStr を inputDateFormatter で指定したフォーマットでパースしてNSDate に格納。それを outputDateFormatter で指定したフォーマットで文字列として出力するサンプルです。 NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; [inputDateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"]; NSString *intputDateStr = @"2000/01/02 03:04:05"; NSDate *inputDate
iPhoneアプリを作っているときに、文字列をUTF-16に変換してから復元すると文字化けするという困った現象にぶちあたりました。 下記のコードを実行します。 NSString *str = @"はろーわーるど"; // UTF-16のchar配列を取得 const char *chars = [str cStringUsingEncoding:NSUTF16StringEncoding]; // 得られたchar配列からNSStringを作成 NSString *str2 = [NSString stringWithCString:chars encoding:NSUTF16StringEncoding]; // 出力 NSLog(@"%@", str2); 結果は次の通りです。 漰贰ﰰ輰ﰰ謰椰 見事、文字化けしました。 原因調査 (1) - エンディアンを指定する Objective-
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く