Reputation: 857
I just upgraded my swift project to swift 3.
I've been using the following function to share the app on Whatsapp, but I couldn't understand the error that occurred after the upgrade
This is the function code:
func shareOnWhatsapp() {
let urlString = "Greetings,\n\nThis is the XYZ App link, I hope you find it useful!\n\nhttp://itunes.apple.com/app/idxxxxxxxx"
let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed())
let url = URL(string: "whatsapp://send?text=\(urlStringEncoded!)")
if UIApplication.shared.canOpenURL(url!) {
UIApplication.shared.openURL(url!)
}
}
The error says:
Contextual member 'urlHostAllowed' has no associated value
Any idea how to resolve this?
Upvotes: 2
Views: 1236
Reputation: 748
You need to get rid of the "()" in the third line:
let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed())
to this:
let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
Upvotes: 5