From the course: iOS Development: Security
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Overriding the file protection level programmatically - iOS Tutorial
From the course: iOS Development: Security
Overriding the file protection level programmatically
- [Narrator] Now, what if we need a different protection level for a particular file? We can do that programmatically. I am going to switch to the view controller. We're going to implement the (unintelligible) method that stores a string to a file using the data protection capabilities. So let's create a private method. I'm going to call it secure save. The first parameter is the text we want to save. It's a type string. We also need a file URL. Of type URL. And let's return a boolean to indicate the result of the execution. I start the implementation by converting the text to data. I use conditional binding since the string's data instance method may return null. Guard let data equals text dot data. And we'll use our UTF 8 coding. If the method returns null, we exit the method by returning false. The data type has a right method that lets us provide options for writing data objects. These options can also include content protection attributes. It's this second one. Now, this method…
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.