Persistence Storage
For any device, there is persistence storage that retains the data even after the power is shut off. Every app in your phone has a persistence space which will remain there unless until you uninstall the app. It is considered as non-volatile storage.
Why We Need it
Say, you have an app which stores the high score of the user whenever he/she crosses the high score. So, the app should remember the high score even when your app is in killed state. Or, App should preserve the high score in all states unless user uninstalls the app.
Similarly, you will have such requirements where you have to store data in local storage (or, storage like iCloud).
Persistence Storage in iOS
- Default System (NSUserDefault)
- Core Data
- Sandboxing & Directories (FileS System)
- Property List
- Sqlite
- iCloud
Here, we are going to discuss about one type of the persistence storage in iOS i.e. NSUserDefault. It is one of the easiest and most used techniques for storing the data in local storage. It is analogous to Preferences in Android.

What NSUserDefault can’t do?
Avoid using NSUserDefault for saving the data in bulk. It is recommended for storing the small chunks of data. NSUserDefault can only store the following types of data:
- UInt
- Int
- Float
- Double
- Bool
- NSData
- String
- NSNumber
- NSDate
- Array
- Dictionary
Demo Project
We are going to create a demo project which will store your dummy name in Persistence Storage.
Step1. Add Navigation Controller in your project. Then, add a label and button with proper constraint on the two visual objects. 
Note: I’m assuming you know how to add constraint and navigation controller.
Step 2. Create action connection of the button and outlet connection of that text field.
Say, I have textFieldName as my text field outlet and buttonSaveData(sender: AnyObject) as button action connection.

Step 3. First, I’ll declare a reference of NSUserDefault type.
- <code>
- //Private Instances
- var defaults:NSUserDefaults?
- </code>
- <code>
- defaults = NSUserDefaults.standardUserDefaults()
- </code>




Prasanna MuraliPosted Sep 5, 2016, 11:05 AM
Nice post......