Database Reference
In-Depth Information
if let imageView = employeePictureImageView {
imageView.image = UIImage (data: employee.picture)
}
This time, you want to use the high-quality version of the picture, since the image
will be shown full-screen. Update the file to use the picture relationship you
created on the Employee entity to access the high-quality version of the picture:
if let imageView = employeePictureImageView {
imageView. image = UIImage (data: employee. picture . picture )
}
There's one more thing to do before you build and run. Open AppDelegate.swift
and find the following line of code in importJSONSeedData() :
employee.picture = pictureData
Now that you have a separate entity for storing the high-quality picture, you need
to update this line of code to set the pictureThumbnail attribute and the picture
relationship. Replace the line above with the following:
employee. pictureThumbnail =
imageDataScaledToHeight (pictureData, height: 120 )
let employeePictureEntity =
NSEntityDescription . entityForName ( "EmployeePicture" ,
inManagedObjectContext: coreDataStack . context )
let pictureObject =
EmployeePicture (entity: employeePictureEntity!,
insertIntoManagedObjectContext: coreDataStack . context )
pictureObject. picture = pictureData
employee. picture = pictureObject
First, you use imageDataScaledToHeight to set the pictureThumbnail to a smaller
version of the original picture. Next, you create a new picture entity using the
EmployeePicture entity description.
You set the picture attributed on the new EmployeePicture entity to the
pictureData constant. Finally, you set the picture relationship on the employee
entity to the just-created picture entity.
Note: imageDataScaledToHeight takes in image data, resizes it to the passed-
in height and sets the quality to 80% before returning the new image data.
Search WWH ::




Custom Search