Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Saving Dictionary with NSAttributed String into a PList or into NSUserDefaults

RkoRko Posts: 63Registered Users
Hi,

I've a Dictionary with an 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 ?\";
};
};
}


I tried Saving this Dictionary as a Plist in the Documents folder
and also,
save the dictionary in NSUserDefaults.
Neither of it worked.
Both methods work if the attributed string in the dictionary is removed.

Code used to save to Plist in Documents folder :

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


Code used to save Dictionary in NSUserDefaults :

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


Someone please help. Am I missing something ?
Post edited by Rko on

Replies

Sign In or Register to comment.