I'm new to iOS programming and having written a simple reminders style app, I'm now rewriting it to implement the MVC model correctly as previously all my code was inside View Controllers.
I have a custom class called Event with properties name, time, repeat etc and then the following structure:
Model class
Retrieves, processes and and saves data to and from NSUserDefaults
RootViewController
Creates an instance of the Model object and asks the model to return all the Events objects from NSUserDefaults
then displays them in a UITableView
EditEventViewController
[editEventVC initWithEvent:theEvent];
Passes the specific event object that was selected in the table cell via init method and displays all the properties available for editing
EditEventPropertyViewController
[editEventPropertyVC initWithValue:propertyValue];
Passes value of property to edit (e.g. event name) via init method and returns the user updated value via a delegate method
Is this the correct way to implement this app?
What's the best way to save the updated Event object in NSUserDefaults
via the Model after finishing with the EditEventViewController? Via a delegate? Currently I am reloading the uitableview data on viewWillAppear in the rootViewController so it will have to save the updated data before retrieving it again.
Thanks
You can store the collection of
Event
inNSUserDefaults
. Since its a custom class, you need to implementNSCoding
protocol for serialization toNSUserDefaults
.You need to archive the data while storing to NSUserDefaults and unarchive when fetching
Hope this will get you started.