pass image in share swift code example
Example: swift share with
import UIKit
class ViewController: UIViewController {
@IBAction func shareTextButton(_ sender: UIButton) {
let text = "This is some text that I want to share."
let textToShare = [ text ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
self.present(activityViewController, animated: true, completion: nil)
}
@IBAction func shareImageButton(_ sender: UIButton) {
let image = UIImage(named: "Image")
let imageToShare = [ image! ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
self.present(activityViewController, animated: true, completion: nil)
}
}