Transforming and Encrypting Data
Although Core Data offers a reasonable array of supported data types, not all data fit neatly into strings, Booleans, numbers, and so on. Core Data offers a catch-all data type, Binary Data, that can store any type of binary data. We used a Binary Data type in Chapter 5, for example, to store images. Core Data marshals any data stored in a Binary Data type to and from an NSData instance. While this means that Core Data can store any kind of arbitrary data in a Binary Data column, it also means that your applications must transform NSData instances into representations useful to your application, and vice versa. While sometimes this may be trivial—with images, for example, creating an image from an NSData instance is as easy as calling UIImage imageWithData: and UIImagePNGRepresentation—in other cases, you may find your code sprinkled with logic to transform raw data to usable data in various places. Wouldn’t it be nice to have Core Data do this transformation work for you?