title: Swift 3 Convert Data to AVAsset or PHAsset
body: <p>I need to convert Data object to AVAsset.</p>
  
  <p>Once I needed to save a video in Realm as Data object. To save it, I converted AVAsset to Data. Now I need to convert it back and save a video to cameraRoll.</p>
  
  <p>Maybe you can suggest some other solutions for this problem?)</p>
  
  <p>Here is how I converted AVAsset to Data:</p>
  
  <pre><code>func convert(phAsset: PHAsset, completion: @escaping (_ data: Data?) -&gt; Void) { 
   PHCachingImageManager().requestAVAsset(forVideo: phAsset,
                  options: nil,
                  resultHandler: { asset, _, _ in
                    guard let asset = asset else { return }
  
                    let exportSession = AVAssetExportSession(asset: asset,
                                             presetName: AVAssetExportPresetHighestQuality)
                    let fileUrl: URL
                    guard let url = asset as? AVURLAsset else { return }
                    fileUrl = url.url
  
                    exportSession?.outputURL = fileUrl
                    exportSession?.outputFileType = AVFileTypeQuickTimeMovie
                    var data = Data()
  
                    exportSession?.exportAsynchronously {
                      do {
                        data = try Data(contentsOf: fileUrl)
                        completion(data)
                      } catch { return }
                    }
     })
  }
  </code></pre>