Skip to main content

The differences between Core Data and a Database



DatabaseCore Data
Primary function is storing and fetching dataPrimary 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" dataWorks 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-userNon-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 memoryOnly operates in memory
Perpetually saved to disk (and often crash resilient)Requires a save process
Can be slow to create millions of new rowsCan create millions of new objects in-memory very quickly (although saving these objects will be slow)
Offers data constraints like "unique" keysLeaves data constraints to the business logic side of the program

Comments

Popular posts from this blog

What's the difference between enum, struct and class?

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...

Adding Swift Convenience Initializers

Designated or Convenience? First a recap on the two types of initializer: A  designated initializer  is the primary initializer for a class. It must  fully initialize all properties introduced by its class before calling a superclass initializer . A class can have more than one designated initializer. A  convenience initializer  is a secondary initializer that  must call a designated initializer of the same class . It is useful when you want to provide default values or other custom setup. A class does not require convenience initializers. The Three rules With that clear you need to remember three rules for designated and convenience initializers for class types: A designated initializer must call a designated initializer from the immediate superclass. A convenience initializer must call another initializer from the same class. A convenience initializer must ultimately call a designated initializer. What does this mean for us? In simp...

What Is a Closure?

Closures are self contained chunks of code that can be passed around and used in your code. Closures can capture and store references to any constants or variables from the context in which they are defined. This is know as closing over those variables, hence the name closures. Closures are use intensively in the Cocoa frameworks – which are used to develop iOS or Mac applications. Functions are a special kind of closures. There are three kinds of closures: global functions  – they have a name and cannot capture any values nested functions  – they have a name and can capture values from their enclosing functions closure expressions  – they don’t have a name and can capture values from their context The thing to keep in mind for the moment is that you already have an intuition about closures. They are almost the same as functions but don’t necessarily have a name. // a closure that has no parameters and return a String var hello: () -> ( String ) = { ...