Writing to filesystem with NSData

The images for Possession instances are created by user interaction and are only stored within the application. Therefore, the Documents directory is the best place to store them. Let’s extend the image store to save images as they are added and fetch them as they are needed. You can use the image key generated when the user takes a picture to name the image in the filesystem.

In this section, you are going to copy the JPEG representation of an image into a buffer in memory. Instead of just malloc’ing a buffer, Objective-C programmers have a handy class to create, maintain, and destroy these sorts of buffers – NSData. An NSData instance holds some number of bytes of binary data, and you’re going to use NSData ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition 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.