title: PHPhotoLibrary error: content editing in performChanges results in error "The operation couldn’t be completed. (Cocoa error -1.)"
body: <p>This is the code that I run on viewDidAppear of a brand new swift app. The <code>info.plist</code> is setup correctly with the <code>Privacy - Photo Library Usage Description</code> key.</p>
  
  <p>The error I get is <code>The operation couldn’t be completed. (Cocoa error -1.)</code></p>
  
  <p>I can create new assets, delete assets, favorite assets, and revert assets... but attempting to edit their content results in this error. I've been attempting to scour the internet for any clue as to how to go about solving this (Stack Overflow, WWDC videos, the <strong>second</strong> page of google, bing and even <em>yahoo</em>). </p>
  
  <pre><code>PHPhotoLibrary.requestAuthorization { (status:PHAuthorizationStatus) in
  
      if status != PHAuthorizationStatus.authorized { return }
  
      let results = PHAsset.fetchAssets(with: nil)
      guard let asset = results.firstObject else { return }
  
      if asset.canPerform(.content) {
  
          let inputOptions = PHContentEditingInputRequestOptions()
          inputOptions.isNetworkAccessAllowed = true
          inputOptions.canHandleAdjustmentData = { (asjustmentData) -&gt; Bool in
              return false
          }
  
          asset.requestContentEditingInput(with: inputOptions, completionHandler: { (input, info) in
              guard let input = input else { return }
  
              guard let inputImageURL = input.fullSizeImageURL,
              let inputImage = CIImage(contentsOf: inputImageURL) else { return }
  
                  guard let eagle = EAGLContext(api: .openGLES2) else { return }
              let context = CIContext(eaglContext: eagle)
              guard let outputImageRef = context.createCGImage(inputImage, from: inputImage.extent) else { return }
              let outputImage = UIImage(cgImage: outputImageRef, scale: 1.0, orientation: .right)
  
              let output = PHContentEditingOutput(contentEditingInput: input)
  
              guard let imageData = UIImageJPEGRepresentation(outputImage, 0.9) else { return }
                  try! imageData.write(to: output.renderedContentURL, options: .atomic)
  
              output.adjustmentData = PHAdjustmentData(formatIdentifier: "myFormat", formatVersion: "1.0", data: Data())
  
              DispatchQueue.main.async {
                  PHPhotoLibrary.shared().performChanges({
  
                      let request = PHAssetChangeRequest(for: asset)
                      request.contentEditingOutput = output
  
                  }, completionHandler: { (success, error) in
                      print(success ? "It worked" : "It failed with error:")
                      print(error?.localizedDescription ?? "No Errors!")
                  })
              }
          })
      }
  }
  </code></pre>
  
  <p><strong>NOTE</strong> on revert, the iOS "Do you want to Edit" dialog appears, however with the code above no dialog appears and the app doesn't crash.</p>