objective c - Saving rich text in NSUserDefaults -
i'm new objective-c , can't find answer problem. i've written simple program using text field enter text, use:
savefbcover1 = cover1.stringvalue; defaultcover1 = [nsuserdefaults standarduserdefaults]; [defaultcover1 setobject:savefbcover1 forkey:@"savecover1"]; [defaultcover1 synchronize]; to save it. after that,
defaultcover1 = [nsuserdefaults standarduserdefaults]; loadfbcover1 = [defaultcover1 objectforkey:@"savecover1"]; fbcoverimagetext = [nsstring stringwithformat:@"%@", loadfbcover1]; to load it. want save , load rich text colors, fonts , on.
for reason, fails save or load properly. can point out mistake?
savefbcover1 getting nsstring cover1.stringvalue, not nsattributedstring, because . looks code saves string properly, , you're getting string when load again, won't attributes because didn't start attributed string, nor did attributes of text in text view , save them separately.
you can attributed string using
savefbcover1 = cover1.attributedstringvalue; however, you're going have little more work save , load string (not much, though). nsattributedstring isn't 1 of types can save directly in nsuserdefaults, you'll need serialize instance of nsdata first. can quite using keyed archiver. read keyed archives in archives , serializations programming guide.
Comments
Post a Comment