Home > 2010 Winter DPS913 > Store a UIImage in Core Data using a value transformer

Store a UIImage in Core Data using a value transformer

At this point in time, you have learned about the types which can be used for Core Data attributes. If you want to store another type, you can use a value transformer.

In this post, we present a “Professors” example app. It is similar in some ways to the “CD Complete” example app, in that it offers a navigation-based style, with viewing and adding/editing of objects.

It also presents two new ideas to you:

  1. Value transformer
  2. Category

A value transformer is an object which packages, and un-packages, objects of a type that isn’t directly supported in a Core Data attribute. We will use a value transformer for a professor photo.

A category enables you to extend a class by adding your own methods. We will use a category to add a method to UIImage that will scale an image to a desired size.

The “Professors” example app

This example app uses Core Data, and enables you to create a list of your professors. You then have fast access to their office number, photo, and website, and can send them an email message.

There are three new concepts shown in this application:

  1. Proper coding of a Cocoa “Category”
  2. The use of a Value Transformer, which enables us to store a UIImage in a Core Data store
  3. The ability to send email from within an application

Download the Professors example app from here.

The first row of screen shots shows the professor list, the “Add professor” screen that appears when you tap the + button, and a professor detail screen that appears when you tap on a row.

prof1small prof6small prof2small

The next row of screens shows the editing screen, the send-an-email screen, and the visit website screen.

prof3small prof4small prof5small


Value Transformer discussion

(more to come)

Category discussion

(more to come)

Categories: 2010 Winter DPS913
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: