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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.