Sometimes it's in a developer's best interest to save data to a file rather than to user defaults. This tutorial shows how to save note data to a file in iOS 10.
- [Instructor] Let's say you want to save your data…to a file instead of saving to user defaults.…So, I'm going to leave this user defaults code here for now.…And so you can see kind of the difference between…saving to a file and saving to user defaults.…So let's scroll up, and the first thing we're going…to need to do is create a reference to a file,…and that's going to be a string,…and it will represent the file path.…So we'll call this "file."…And it's a string and we can't set the value yet,…so I'm going to make it an implicitly unwrapped optional,…so we'll add an exclamation point.…
Now above where we call the load method…inside view did load,…I am going to create a few new lines.…Now I'm going to define the file.…Now we need to save files in iOS in the application's…documents directory.…So let's look at how to get to that directory.…So, we'll create a constant called "docs dir."…Short for docs directory.…And this is going to be…NS search path for directories in domains,…and this returns a string array.…
So it's going to find a directory.…
In this course, join Todd Perkins as he takes you through how to create cross-platform apps using Swift. This course is one of three related courses designed to help you discover the similarities and differences that exist between the platforms used by three main devices: an Android phone, an iPhone, and a Windows phone. These courses use the same assets to create the same note-taking app so that you can identify and experience the complementary and contrasting development steps.
- Downloading Xcode
- Configuring preferences in Xcode
- Building the app interface
- Connecting interface elements to code
- Writing app logic
Skill Level Intermediate
1. Project Overview
A demo of the finished app1m 19s
2. Understanding iOS Specifics
3. Get Started
4. Create the Table and a Data Source
5. Edit and Save Data
6. Work with Multiple View Controllers
Next steps2m 1s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.