0

Im getting this error while building iOS app.

Error showing on the line which I Bolded here

This is my code

@available(iOS 8.0, *)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    **guard let dynamicLinks = DynamicLinks.dynamicLinks() else {**
        return false
    }
    let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        self.openURL(url: userActivity.webpageURL!)
    }

    if !handled {
        if let url = userActivity.webpageURL?.absoluteString {
            self.openURL(url: URL(string: url)!)
        }
    }
    return handled
}
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • It seems that that function doesn't return an optional, so you can't use a conditional assignment. – Paulw11 Oct 06 '18 at 09:51
  • The **bold** tag has no effect within a code section. `dynamicLinks()` is obviously a non-optional so the guard statement is pointless. just write `let handled = DynamicLinks.dynamicLinks().handleUniversalLink...` – vadian Oct 06 '18 at 09:52
  • @vadian i believe he was trying to show where his error was. :) – Rakesha Shastri Oct 06 '18 at 09:53
  • You do not need conditional assignment there. Replace the `guard let` with a simple assignment `let dynamicLinks = DynamicLinks.dynamicLinks()` – Rakesha Shastri Oct 06 '18 at 09:53
  • @RakeshaShastri hi I replace the code with "let" but the error is still showing – Cebaca App Oct 06 '18 at 10:08
  • @vadian I tried this let handled = DynamicLinks.dynamicLinks().handleUniversalLink... but error is still there – Cebaca App Oct 06 '18 at 10:11
  • I meant to delete also the entire `guard` expression. – vadian Oct 06 '18 at 10:12
  • @vadian after removing that expression I'm getting this error "Use of unresolved identifier 'dynamicLinks'" – Cebaca App Oct 06 '18 at 10:19
  • If `DynamicLinks.dynamicLinks()` throws the *conditional binding* error the compiler does know the identifier. Are you sure you added the parentheses after `dynamicLinks` ? – vadian Oct 06 '18 at 10:23

1 Answers1

0

Apparently DynamicLinks.dynamicLinks() doesn't yield an optional result. Change your code to this:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    let dl = DynamicLinks.dynamicLinks()

    let handled = dl.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        self.openURL(url: userActivity.webpageURL!)
    }

    if !handled {
        if let url = userActivity.webpageURL?.absoluteString {
            self.openURL(url: URL(string: url)!)
        }
    }
    return handled
}
ielyamani
  • 17,807
  • 10
  • 55
  • 90