将带有NSAttributed String的字典保存到PList或NSUserDefaults中

时间:2011-10-19 17:37:35

标签: ios save plist nsuserdefaults nsattributedstring

我有一个带有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 ?";
        };
    };
}

我尝试将此词典保存为Documents文件夹中的Plist 并且, 将字典保存在NSUserDefaults中。 它们都没有用。 如果删除了字典中的属性字符串,则这两种方法都有效。

用于保存到Documents文件夹中的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"];

有人请帮忙。我错过了什么吗?

1 个答案:

答案 0 :(得分:-1)

一个有趣的实施。 猜猜这是一个解决方案:

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

现在将探讨这个问题。