Question

Things are getting messy in my app so would like to do a clean up. The first thing that has come to mind is to take my NSDictionary which is my model for my app and put it into it's own file. I feel this would give me much more flexibility.

I know that this is possible but how do I go about doing this? My search for information has failed.

Any guides or tutorials you can link me to would be helpful.

UPDATE

Imagine 3 controllers:

CollectionViewController 1 - (Displays clothing items. The next controller is pushed when a button called "refine" is tapped)

TableViewController 2 - (Displays a list of filtering options e.g. refine by colour, size. The next controller is pushed depending on what row button was tapped.)

ViewController 3 - (Displays switches to turn on filtering options. When selection for a page is made a done button is tapped and I'm taken back to TableViewController 2)

Now a customer needs to know what has been selected for each filter by option in TableViewController 2. So let's say for gender they selected "male" for colour they selected "blue", "green" and "black". There is a label just underneath the specific rows title that will display these selections.

Gender -male

Colour - blue, green, black

This way they know what they have selected. I also need to pass the state of the switch. The goal here is to make it so the user can go back to CollectionViewController 1 and return back to TableViewController 2 and still see what has been selected and go back to ViewController 3 and see what was switched on.

I needed a sensible way to keep track of my data. Setting everything controller by controller in the h files became messy. I found myself creating properties over and over again.

From what I've read via the web I've decided not to take the singleton route.

Was it helpful?

Solution

Short answer: Don't do that.

Longer answer: The model of an iOS (or more generally an object oriented) application should be at least in it's own class(es). Therefore create a subclass of NSObject and add properties suitable to represent the data of your App.

If you have more than one model object you may have those in an array or a set. To persist the array (or the set) you can use Core Data, sqlite or NSCoding. Those names should help you with your search how to do this.

OTHER TIPS

The best design for a simple TableView app is generally an NSMutableArray containing NSMutableDictionary entries for the individual table rows.

But for anything more complex one would have to see the structure of the data and the structure of the app. And we'd also need to know how persistent the data needs to be, to know whether it should be represented in a database vs a runtime structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top