| Database | Core Data |
| Primary function is storing and fetching data | Primary function is graph management (although reading and writing to disk is an important supporting feature) |
| Operates on data stored on disk (or minimally and incrementally loaded) | Operates on objects stored in memory (although they can be lazily loaded from disk) |
| Stores "dumb" data | Works with fully-fledged objects that self-manage a lot of their behavior and can be subclassed and customized for further behaviors |
| Can be transactional, thread-safe, multi-user | Non-transactional, single threaded, single user (unless you create an entire abstraction around Core Data which provides these things) |
| Can drop tables and edit data without loading into memory | Only operates in memory |
| Perpetually saved to disk (and often crash resilient) | Requires a save process |
| Can be slow to create millions of new rows | Can create millions of new objects in-memory very quickly (although saving these objects will be slow) |
| Offers data constraints like "unique" keys | Leaves data constraints to the business logic side of the program |
Enums An enum is considered as a structured data type that can be modified without needing to change say a String or Int multiple times within your code, for example the below shows how easy it would be to change something by accident and forget to change it somewhere else. let myString = "test" if myString == "ttest" { // Doesn't execute because "ttest" is the value assigned to "myString" } With a enum we can avoid this and never have to worry about changing the same thing more than once enum MyEnum : String { case Test = "test" } let enumValue = MyEnum . Test if enumValue == MyEnum . Test { // Will execute because we can reassign the value of "MyEnum.Test" unless we do so within "MyEnum" } Structs I'm not sure how much you know about the MVC pattern but in Swift this is a common practise, before I explain how structs are useful I'll...
Comments
Post a Comment