3

I'm a relatively new iOS developer, with most of my previous experience coming from .NET. My application is a canvas like system in that there is a parent UIView that contains all the objects the user is placing/resizing/etc as subviews. I want to be able to save these positions/configurations to named files.

In .NET, I would have simply subclassed UIView, given it a "title" property, then serialized this to file, and then deserialized them to load them back, but in Cocoa I'm quite lost.

Originally I thought I could do this using NSCoding, but this doesn't seem to be a good solution for multiple file saving.

So I looked at Core Data, but I'm not sure how I can create Core Data objects of existing Cocoa UIKit classes like UIView.

I've spent a while googling and can't find any information about this kind of predicament. What should I use, and what is the best way to go about it?

1 Answers1

4

You probably could do it with NSKeyedArchiver, since UIView implements NSCoding. A more MVC-oriented design, however, would be to have the user manipulate a data model by moving the views around. To save, you'd archive the model rather than the views themselves.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 2
    I agree - storing archived views as models isn't a great idea. Also, if you save archived UIKit classes, you run the risk of encountering trouble when users update the OS, for example, and classes change, making your saved data incompatible. – Michael Tyson Mar 24 '11 at 14:43