Ans : There are SIX types of persistent storage.
1. Userdefaut
2. Property List
3. Sqlite
4. Keychain
5. Files
6. Coredata
If brief answer they asked then follow :
1. Userdefaut : NSUserDefault class allow us to store small amount of data. It can store NSData, NSString, NSArray, NSDictionary, NSNumber,
The maximum data can we saved depends on iOS. Currently it can store 4GB of data.
But if file is too large, then it takes too much time for retrieve and write data in file. So we can save small amount of data only. Otherwise it waste time.
We can also store our custom objects in userDefaults. We achieve this by conforming our class to NSCoding protocol. We can then convert our custom object into NSData with the help of NSKeyArchiver class. The NSData is then stored into userDefaults like other objects. Similarly we can get NSData from userDefaults and then using NSKeyUnarchiver convert the NSData back to our custom objects.
2. Property List : As userdefaut save data in plist file, so like userdefaut, Property List is not also made for save large amount of data. There is one method of NSArray and NSDictionary as writeToFile for saving data.
3. Sqlite : If your application deals with large amount of data with relationship then we should use sqlite. It's API is written in C language and embedded with our application so it is very fast. There are ORM for bringing gap between obj c app and sqlite like, FMDB, Realm
4. Keychain : If you want to save highly sensitive and secure data like passwords and secret codes then there is a good news for you. Storing data in keychain is most secure way. To store data, I have taken library named SwiftKeyChainWrapper from cocoapods.
To Save data in Keychain :
let saveSuccessful: Bool = KeychainWrapper.standard.set("Some String", forKey: "myKey")
To get data from Keychain :
let retrievedPassword: String? = KeychainWrapper.standard.string(forKey: "userPassword")
To remove data from keychain :
let removeSuccessful: Bool = KeychainWrapper.standard.remove(key: "myKey")
5. Files : You can save data to any type of file. There are three type of folder like Document, Library, Tmp fo saving various type of file.
6. Core Data : Apple’s solution for persistence allows applications to persist data of any form and retrieve it. It isn’t technically a database, although it usually stores its data in one (an SQLite DB). It’s not an object-relational mapper (ORM), though it can feel like one. It’s truly an object graph, allowing you to create, store, and retrieve objects that have attributes and relationships to other objects. Its simplicity and power allow you to persist data of any form, from basic data models to complex.
No comments:
Post a Comment
Thanks