// // ActionViewController.swift // CocoaPods-Mix-Action // // Created by Florent Vilmart on 17-05-09. // Copyright © 2017 ampme. All rights reserved. // import UIKit import MobileCoreServices import Moya class ActionViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Get the item[s] we're handling from the extension context. // For example, look for an image and place it into an image view. // Replace this with something appropriate for the type[s] your extension supports. var imageFound = false for item in self.extensionContext!.inputItems as! [NSExtensionItem] { for provider in item.attachments! as! [NSItemProvider] { if provider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) { // This is an image. We'll load it, then place it in our image view. weak var weakImageView = self.imageView provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil, completionHandler: { (imageURL, error) in OperationQueue.main.addOperation { if let strongImageView = weakImageView { if let imageURL = imageURL as? URL { strongImageView.image = UIImage(data: try! Data(contentsOf: imageURL)) } } } }) imageFound = true break } } if (imageFound) { // We only handle one image, so stop looking for more. break } } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func done() { // Return any edited content to the host app. // This template doesn't do anything, so we just echo the passed in items. self.extensionContext!.completeRequest(returningItems: self.extensionContext!.inputItems, completionHandler: nil) } }