Writing to the Filesystem with NSData

Your archiving in Homepwner saves and loads the itemKey for each Item, but what about the images? At the moment, they are lost when the app enters the background state. In this section, you will extend the image store to save images as they are added and fetch them as they are needed.

The images for Item instances should also be stored in the Documents directory. You can use the image key generated when the user takes a picture to name the image in the filesystem.

Implement a new method in ImageStore.swift named imageURLForKey(_:) to create a URL in the documents directory using a given key.

func imageURLForKey(key: String) -> NSURL {

    let documentsDirectories =
        NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.