この質問に対する受け入れられた回答に基づいて、次のコードを作成しました。
NSData* somedata;
somedata=[NSKeyedArchiver archivedDataWithRootObject:ts];
ここで、ts は、いくつかのテキストといくつかの属性 (この場合は色) が取り込まれた NSAttributedString です。
このコードを実行すると、次のエラーが表示されます。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x6eb5b90'
私は NSCoder の分野に不慣れですが、前述の質問に対する答えから、これが私がしなければならないすべてのように思えました。それは...ですか?私は何か見落としてますか?
編集:
この場合の認識されないセレクターは、NSAttributedString の色属性に送信されています。次のように文字列を初期化すると:
NSAttributedString *ts = [[NSAttributedString alloc] initWithString:text attributes:self.currentAttributeDictionary];
辞書は次のように作成されます。
self.currentAttributeDictionary=[NSDictionary dictionaryWithObjectsAndKeys:
[self.currentColor CGColor],(NSString*)kCTForegroundColorAttributeName,
nil];
そして、辞書の NSLog はこれをもたらします:
New dictionary is: {
CTForegroundColor = "<CGColor 0x6eb5b90> [<CGColorSpace 0x6e968c0> (kCGColorSpaceDeviceRGB)] ( 1 1 0 1 )";}
上記の CGColor のアドレスは、エラー メッセージのアドレスと一致します。