From the course: Code Clinic: Swift

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Import data

Import data - Swift Tutorial

From the course: Code Clinic: Swift

Start my 1-month free trial

Import data

- [Instructor] Now, let's connect to our database. We'll start by creating a property in our ViewController class called realm. The type of that is going to be a Realm and we'll make it an implicitly unwrapped optional. Let's scroll down to load realm now. And we're going to write the code to connect to the database. The first task here is to make sure that we copy this dayData file over into the documents directory of our application. If it's already been copied there, we don't need to copy it again. So the first test is to find the URL that it should be saved at. So first, we'll reference a fileManager. And I'm going to wrap everything inside of a docatch statement. So we'll delete everything inside of the do statement. Catch statement and then in there, I'm going to print any error message that we happen to get. So inside the do statement, we'll reference a fileManager. So let fileManager equal FileManager.default. You don't really need that. It just saves a little bit of code on…

Contents