0
0
iOS Swiftmobile~10 mins

Deep linking in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to handle a URL in the AppDelegate method.

iOS Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return [1]
}
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
Cnil
Durl.isFileURL
Attempts:
3 left
💡 Hint
Common Mistakes
Returning false causes the system to think the URL was not handled.
Returning nil is invalid because the method expects a Bool.
2fill in blank
medium

Complete the code to extract the host from the incoming URL.

iOS Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let host = url.[1] else { return false }
    print("Host: \(host)")
    return true
}
Drag options to blanks, or click blank then click option'
Apath
Bhost
Cscheme
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using url.path returns the path after the host, not the host itself.
Using url.scheme returns the protocol like 'https'.
3fill in blank
hard

Fix the error in the code to correctly parse query parameters from the URL.

iOS Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
    if let queryItems = components?.[1] {
        for item in queryItems {
            print("\(item.name): \(item.value ?? "")")
        }
    }
    return true
}
Drag options to blanks, or click blank then click option'
Aparameters
BqueryParameters
CqueryItems
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' or 'parameters' causes a compile error because those properties do not exist.
Forgetting to unwrap optional components.
4fill in blank
hard

Fill both blanks to create a URL scheme check and handle it.

iOS Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if url.[1] == "myapp" {
        // Handle the URL
        print("Custom scheme detected")
        return [2]
    }
    return false
}
Drag options to blanks, or click blank then click option'
Ascheme
Bhost
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Checking host instead of scheme for the URL type.
Returning false even after handling the URL.
5fill in blank
hard

Fill all three blanks to safely unwrap the URL, check the scheme, and extract the path.

iOS Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    guard url.[1] == "myapp" else { return false }
    let path = url.[2] ?? ""
    print("Path: \(path)")
    return [3]
}
Drag options to blanks, or click blank then click option'
Ascheme
Bpath
Ctrue
Dhost
Attempts:
3 left
💡 Hint
Common Mistakes
Not unwrapping the optional URL before use.
Checking host instead of scheme.
Returning false even after handling the URL.