UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: UIKit Project 32 - "Use of unresolved identifier window" in AppDelegate

Forums > Books

So at the end of the chapter, to handle activation events coming from Spotlight, we're told to place the following into our AppDelegate class:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if (userActivity.activityType == CSSearchableItemActionType) {
        if let uniqueIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String {
            if let navigationController = window?.rootViewController as? UINavigationController {
                if let viewController = navigationController.topViewController as? ViewController {
                    viewController.showTutorial(Int(uniqueIdentifier)!)
                }
            }
        }
    }

    return true
}

Even copying right out of the book, however, it indicates that window is an unresolved identifier, and shows a compiler error.

Is this a version/upgrade issue, or should there be a property added to AppDelegate to handle this?

3      

Hi, starting with iOS 13, handing these is done in SceneDelegate. You should all the method there with modifications.

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {

    }

6      

That did it! Only other note, besides of course moving over the import CoreSpotlight call is to remove the return true call at the end of the function, since the new version is a void function.

Thanks!

5      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.