0

私は辞書を持っていますNSAttributtedString

{
    9 =     {
        9x0 =         {
            UserID = 123;
            formattedMessage = "Hi... How are you ?{\n    CTForegroundColor = \"<CGColor 0x601e460> [<CGColorSpace 0x6010020> (kCGColorSpaceDeviceGray)] ( 0 1 )\";\n    NSFont = \"CTFont <name: Cochin-BoldItalic, size: 17.000000, matrix: 0x0>\\nCTFontDescriptor <attributes: <CFBasicHash 0x6070640 [0x11f8400]>{type = mutable dict, count = 1,\\nentries =>\\n\\t1 : <CFString 0xf4d5c4 [0x11f8400]>{contents = \\\"NSFontNameAttribute\\\"} = <CFString 0x60707f0 [0x11f8400]>{contents = \\\"Cochin-BoldItalic\\\"}\\n}\\n>\";\n}";
            isDeleted = 0;
            isEdited = 0;
            lastModifiedDate = "2011-10-19 17:27:38 +0000";
            message = "Hi... How are you ?";
        };
    };
}

この辞書をPlistとしてDocumentsフォルダーに保存し、辞書をに保存してみましたNSUserDefaults。どちらも機能しませんでした。辞書の属性付き文字列が削除された場合、両方の方法が機能します。

ドキュメントフォルダのPlistに保存するために使用されるコード:

NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *aFilePath = [NSString stringWithFormat:@"%@/ChatHistory.plist",aDocumentsDirectory];
BOOL aStatus = [aDictionary writeToFile:aFilePath atomically:YES];

辞書を保存するために使用されるコードNSUserDefaults

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:aDictionary forKey:@"ChatHistory"];

誰か助けてください。私は何かが足りないのですか?

4

1 に答える 1

-1

興味深い実装。これが解決策だと思います:

https://devforums.apple.com/message/340283#340283

これを今探求します。

于 2011-10-20T09:57:43.260 に答える