---
title: "#58: Photo Editing Extensions 🎑📝"
url: https://littlebitesofcocoa.com/58-photo-editing-extensions
author: Jake Marsh
date: 2015-08-12
published: 2015-08-12
topics: ["Extensions","Photos"]
description: "Photo Editing Extensions are a powerful way for apps to integrate with the system Photos app. Users can begin editing a photo, jump into a third-party..."
---

# #58: Photo Editing Extensions 🎑📝

By Jake Marsh, August 12, 2015. HTML: https://littlebitesofcocoa.com/58-photo-editing-extensions

**Photo Editing Extensions** are a powerful way for apps to integrate with the system Photos app. Users can begin editing a photo, jump into a third-party extension, and return seamlessly back to the system editing interface. Let's try making one.

We begin by adding a new **Photo Editing Extension** target to our project.

<img src="https://media.littlebitesofcocoa.com/bite-assets/058-photo-editing-extensions-photo-editing-extension-target.png" style="max-width: 58px;" />

Our extension will use **CoreImage** (covered in [Bite #32](http://littlebitesofcocoa.com/post/123470467088/32-coreimage-basics)) to convert a photo to black and white. The basic workflow goes like this:

1. User launches our extension while editing inside **Photos.app**
2. a `PHContentEditingInput` object is handed to us via the startContentEditingWithInput... function
3. User performs the edits they would like using our view controller
4. User taps **Done** button (provided by the system)
5. System asks us for a `PHContentEditingOutput` object containing our changes to the image via `finishContentEditingWithCompletionHandler`.

<img src="https://media.littlebitesofcocoa.com/bite-assets/058-photo-editing-extensions-workflow.png" style="max-width: 535px;" /><br />

Let's move on to the code.

Along with the input object, we also receive a `placeholderImage` which we'll use as the initial image in our own image view.

``` swift
func startContentEditingWithInput(contentEditingInput: PHContentEditingInput?, placeholderImage: UIImage) {
  input = contentEditingInput
  imageView.image = placeholderImage
}
```

After processing, we create an output using the intial input object we were handed, and write our modified image to it's content URL.

``` swift
let output = PHContentEditingOutput(contentEditingInput: input)

processedImageData.writeToURL(
  output.renderedContentURL, 
  atomically: true
)
```

Lastly, we describe our adjustments, so we can be a good citizen in **Photos.app's** non-destructive editing world.

``` swift
output.adjustmentData = PHAdjustmentData(
  formatIdentifier: NSBundle.mainBundle().bundleIdentifier!,
  formatVersion: "1.0",
  data: "Grayscale".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
)
```

Download the complete project here: [j.mp/bite058](http://j.mp/bite058)
