Writing to the Filesystem with NSData

Your archiving in Homepwner saves and loads the itemKey for each BNRItem, but what about the images themselves? Let’s extend the image store to save images as they are added and fetch them as they are needed.

The images for BNRItem 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.

Open BNRImageStore.m and add a new method declaration to the class extension.

-​ ​(​N​S​S​t​r​i​n​g​ ​*​)​i​m​a​g​e​P​a​t​h​F​o​r​K​e​y​:​(​N​S​S​t​r​i​n​g​ ​*​)​k​e​y​;​

Implement imagePathForKey: in BNRImageStore.m to create a path in the documents directory using a given key.

-​ ​(​N​S​S​t​r​i​n​g​ ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.