I want to add a share button into my view. My app has multiple views. I created a function. When I try to put this function into my main view which is contentview, it works as I expected but when I put this function into a different view it crashes I don’t understand why this is happening. The function I created is as following...
func shareContent(){
tap1.toggle()
let url = URL(string: "http://apple.com")
let ac = UIActivityViewController(activityItems: [url!], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(ac, animated: true, completion: nil)
}