开发者

Best way to store text, font, and color in iPhone? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel tha开发者_如何转开发t this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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:

  1. Storing the data you want, and
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜