Database Reference
In-Depth Information
The app uses a standard UIImagePickerController to add photos as attachments to
notes.
Note: To add your own images to the Simulator's photo album, drag an image
file onto the open Simulator window. Thankfully, the iOS 8 Simulator now
comes with a library of photos ready for your use. :]
If you're using a device, go to AttachPhotoViewController.swift and set the
sourceType attribute on the image picker controller to .Camera to take photos
with the device camera. The existing code uses the photo album, since there is
no camera in the Simulator.
Add a couple of sample notes with photos, since in the next section you'll be using
sample data from this state of the project to move forward with a slightly more
complex migration.
Note : At this point, you might want to make a copy of the v2 source code into
a different folder to come back to later. Or if you're using source control, set a
tag here so you can come back to this point.
A manual migration
The next step in the evolution of this data model is to move from attaching only a
single image to a note to allowing the user to attach multiple images. The note
entity will stay, and you'll need a new entity for an image. Since a note can have
many images, there will be a to-many relationship.
Splitting one entity into two isn't exactly on the list of things lightweight migrations
can support. It's time to level up to a custom manual migration!
The first step in every migration is to create a new model version. As before, select
the UnCloudNotesDataModel.xcdatamodeld file and from the Editor menu
item, select Add Model Version... . Name this model UnCloudNotesDataModel
v3 and base it on the v2 data model. Set the new model version as the default
model and open it in Xcode to start making the necessary changes.
First, you'll add a new entity to the new data model. In the lower-left corner, click
the Add Entity button. Rename this entity Attachment . Select the entity and in
the Data Model inspector pane, set the Class to UnCloudNotes.Attachment .
 
Search WWH ::




Custom Search