Best way to store text, font, and color in iPhone? [closed]
I'm working on a text editor iPhone app where a user can type and save a note with custom font, size, and color. So I have an NSString
, UIFont
, and a UIColor
. I need to store all these in some sort of data structure, but I'm not sure what would be the best method. Currently I'm using an NSMutableArray
which writes to a plist for the string, and two other NSMutableArray
of custom objects that save to NSUserDefaults
on exit. But this is getting way too complicated to manage and debug. Is there any better way to do this?
I would create a custom NSObject subclass, called AttributedText. It would store these values using custom setters and could be retrieved from the data store with custom getters too. You could easily make it save to NSUserDefaults, if you used this custom object.
Your way is the most straightforward already. If you're looking for something a bit cleaner, you might consider building a small custom object that is responsible for:
- Storing the data you want, and
- Saving/loading in
NSUserDefaults
as needed
Define a simple getter/setter API on the object for the data you want, and use it to separate out the complexity of dealing with the arrays and user defaults. (You'll use most of the same implementation you already have, just in a different class.)
I'd just store an attributed string.
精彩评论