Core Data using Swift 2.1 iOS

Today we will start our tutorial on a Notes App and saving them in Core Data using Swift 2.1 iOS. In our past Tutorial we created a Simple TableView you can check it out here. So on top of that we will be storing that data in Core Data using Swift2.0 iOS.

What is Core data : is an object graph and persistence framework. It allows data organised by the relational entity–attribute model to be serialised into XML, binary, or SQLite stores. The data can be manipulated using higher level objects representing entities and their relationships. Core Data interfaces directly with SQLite.

Using Core Data in Swift is much simpler then using it in Objective C.

  1. Saving data in core data : Suppose we have an entity Name “Person” and attribute named “name” of type String.
    Core Data using Swift 2.1 iOS

Let start saving some data into it Create a method to save and add the following code :

Saving data in Core Data never been this simple, right!!


2. After saving data now lets Fetch data from Core Data. For Fetching we use NSFetchRequest.

We can also use NSPredicates to customise our fetching for eg. we only want to fetch something specific then we can use Predicate


Above is the simplest way to save and fetch data from Core Data using Swift 2.1 iOS.


Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.