iOS has more than one local databases like CoreData, Keychain, UserDefault. All 3 databases do the same thing, Saving, Updating, Selecting, etc. Are there any different between them, like security, memory or speed? When using (CoreData, UserDefaults, Keychain) more powerful than others?
-
1Each have completely different uses. Please read the documentation for each and then update your question with more details about what you need clarified. – rmaddy Jan 25 '19 at 22:57
2 Answers
Not everything , but in short
Userdefaults : is used for saving settings data. It's not to be used for temporary data across viewControllers. It's the fastest as it's plist file or a dictionary when it comes to running state of the app
CoreData : is a relational database used for large data storage , creates models automatically from simple UI and it's a sqlite-based
- Keychain : is the most secure and always used for sensitive data like tokens , passwords etc. But it's also the slowest one as it's a c - wrapper.

- 33,269
- 19
- 164
- 293

- 98,760
- 8
- 65
- 87
-
Thanks to answer me . I used them randomly. Now I have some idea about them. – Omer Tekbiyik Jan 25 '19 at 22:47
-
1Core Data is not specifically a database or backed by SQLite. That's just the most common use. – rmaddy Jan 25 '19 at 22:59
-
CoreData is not a database ?? it is even it's UI supports that it's a relational also – Shehata Gamal Jan 25 '19 at 23:02
-
2Core Data is for managing object graphs. It support 4 possible persistence models. The SQLite database is just one of the 4 options. – rmaddy Jan 25 '19 at 23:21
-
Core data is an object graph mapper. Just because Core Data is a data persistent doesn't mean that it is a database – Aji Saputra Raka Siwi Jul 21 '21 at 07:16
NSCoding/NSKeyedArchiver vs. Core Data doesn't directly answer your question. But it's very helpful. Long story short: Core data is a pain in the neck but when it comes to modeling, querying, traversing and persisting complex object graphs, there is no substitute for Core Data. Core Data is a big hammer, but not every problem is a nail—much less a sufficiently large nail.
KeyChain is more like a vault. You store small limited information in it e.g. password. You don't store the entire database in it. It acts like a gatekeeper "Can this user open the app? Yes? Ok let's open up our data base and show core data entries..."
UserDefaults are like the last page a user was at. You may store a single custom object, but don't store a big record of it.

- 33,269
- 19
- 164
- 293
-
Thanks to answer me . I used them randomly. Now I have some idea about them. – Omer Tekbiyik Jan 25 '19 at 22:47
-
the userdefault shouldn't be used to store objects at all even if small – Shehata Gamal Jan 25 '19 at 22:48
-
@Sh_Khan I don't get you. Can you clarify? I'm asking because I also see: [`set(_:forKey:)`](https://developer.apple.com/documentation/foundation/userdefaults/1414067-set) – mfaani Jan 25 '19 at 22:50
-
@Honey this used for data like `[1,2,"awea",1.22]` what i meant is that it's not for a custom object – Shehata Gamal Jan 25 '19 at 22:58