Configure deep links in swift?

24 viewsappdelegatedeep linkingiosswift
0

So I have an app written in swift that I would like to use deep links for. A user would click on one that in the route of the URL had different pieces of information such as the id of the post or the number of likes it has or something like that. I understand that you put this in the AppDelegate:

func application(application: UIApplication,openURL url: NSURL,sourceApplication sourceApplication: String?,annotation annotation: AnyObject?) -> Bool {
    println(url.host as String!)
    return true
}

And that prints everything after appname://. But how can I get url.host to my view controller to be parsed into the information I need. If the declaration of URL was outside of that function then I could use this:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let InfoFromDeepLink = appDelegate.url.host

but since it’s inside of that bulky Objective-C function, I’m helpless. How do you do this? I’m completely baffled. I can’t even set the function to return url.host because it doesn’t allow that. That’s what I would do in Javascript. If you also know Javascript maybe put it in terms that a web developer would understand because I’m pretty new to this. This has to be so simple for a Swift developer right? I feel so stupid.