NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Swift on Sundays: Friendzone - AppDelegate or SceneDelegate?

Forums > Books

Hi,

I've been following the FriendZone chapter in Swift on Sundays, but haven't been able to get the coordinator working. I think it is due to the code to create the coordinator, which the book says to add to the willConnectTo method of SceneDelegate.swift. I took a look at the GitHub repository for this app to see where I was going wrong, and this doesn't have a SceneDelegate.swift, and instead the code is in AppDelegate.swift. I also tried removing SceneDelegate.swift from my project and putting the logic in AppDelegate, but that didn't work either. So I'd really just like to know why the difference between the GitHub repo and the book, and which is correct.

1      

The github repository was last updated 16 months ago, which is prior to WWDC19 introducing the new SceneDelegate class and way of doing things. The book, however, was last updated in Feb 2020 and therefore includes SceneDelegate and the new method.

2      

I found the solutiom by looking at someone else's version in GitHub. It seems that in SceneDelegate, instead of:

window = UIWindow(frame: UIScreen.main.bounds)

I should be doing:

guard let windowScene = (scene as? UIWindowScene) else { return } // this line already there ... window = UIWindow(windowScene: windowScene)

3      

Thanks for posting that solution, I was having the same problem!

1      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.