When building an application, you often need some way to store associated data. Applications usually store less data than cloud applications, but many of the same constraints still exist. You still need to store data.
Some of the data is relational, such as contacts or addresses. And having the ability to store relational data in an application running on a phone or Mac application makes a lot of sense.
There are a few options when we need to store relational data, but the easiest is SQLite. SQLite is well supported on Mac and iOS as a data store. In this post, we will create a contact record in an SQLite database.
First, we will create an App using Xcode.
We will need a package to support SQLite.
Now we can create a Swift file for storing data in SQLite.
We can create our new tables pretty easily.
We can write data to our contacts table with straightforward SQLite code.
Here’s the complete data access code.