I have a UIViewController for user to input their data and submit to our ASP.NET Webapi. there are about 40 textField and other controls.
Is there any way i can save the input locally. the data will not be clear until user click the submit button. I want the data still there even restart the phone or restart the program. save in XML ?
There are quite a few options that you could choose from, ranging in complexity as follows:
Use an NSKeyedArchiver to save to the local filesystem. This involves making your model class conform to the NSCoding protocol.
Use sqlite and a local database. The C api can be quite verbose, however there is a nice Objective-C wrapper called FMDB.
Use CoreData. This involves creating a local data-model (object schema) and then instructing CoreData to persist the object to its storage. Storage is typically an sqlite database (includes ACID compliance - eg transactions, atomicity, etc), but CoreData also knows how to do binary and XML formats.
Whichever approach you use, I recommend using the Data Access Object (DAO) design pattern, which provides a protocol for persistence methods. Examples:
- (Customer*) findCustomByLastName:(NSString*)lastName
- (void) save:(Customer*)customer
. . in this way its possible to start with a very simple style of persistence, to test how your overall architecture integrates into a cohesive app, and then swap in another more robust style later. Here's an example of a file-system DAO using NSKeyedArchiver.
Other approaches:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With