DEV Community

KeeyboardKeda
KeeyboardKeda

Posted on

#100DaysOfSwift: Project 13

Hello, project 13 introduced me to CIContext, CIFilter, and UIImageWriteToSavedPhotosAlbum. The project was to allow the user to add filters to a picture and save it in their photos album.

Key Takeaways:

  1. IBOulet connects the storyboard to your code and is used by Xcode to understand which properties and methods are relevant to IB. IBAction is a way of making your storyboard layout trigger code.

  2. Picker.delegate : delegate receives notifications when the user picks an image, movie or exits the picker interface. Picker must have a delegate because it decides when to dismiss the picker interface.

  3. After the user selects the image they want to add a filter to, we added a method where we check if the image selected was an UIImage and input it as the value for the variable currentImage. Example,

func imagePickerController(_picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.Infokey: Any]){

guard let image = info[.editedImage] as? UIImage else {return}

dismiss(animated: true)

currentImage = image
}

  1. CIImage is created from the UIImage selected by the user that is stored in the currentImage property and KCIInputImageKey is a key for the CIImage object to use as an input image. Example,

let beginImage = CIImage(image: currentImage)
currentFilter.setValue(beginImage, forKey: KCIInputImageKey)

  1. CIContext stands for Core Image Context and it handles rending. CIFilter store the filer the user activated.

Top comments (0)