From the course: Building a Note-Taking App for iOS 11 with Swift
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Save data to a file
From the course: Building a Note-Taking App for iOS 11 with Swift
Save data to a file
- [Instructor] To save data to a file, we're going to start with our user defaults saving code and modify it. The first thing that we need that's different is a file url and that's going to be a URL type that is a reference to the file that we want to save. So, I'm going to create a new instance variable called fileURL that's of the type URL and this is going to be an implicitly unwrapped optional. The reason for that is we can't give it a value on this line we actually need to wait for a little bit so we're going to give it a value inside of viewDidLoad. So, scroll down there and we want to go above the load method. So, we want to have that fileURL before we attempt to load the file. To do that, we need to start with a baseURL. So, we need to get the fileURL for the documents directory. This is going to be a long line of code. So, what I'm going to do is hide the navigator and then I'm going type in let baseURL. This is going to be of the type URL but I'm going to type that just to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.