简体   繁体   中英

How to access SceneDelegate from NSObject?

I declared a variable in sceneDelegate and want to access that variable from the NSObject. We can do that from UIView or UIViewController, but don't know how to do this in NSObject.

Is there a way to access this variable?

If you have only one scene in application it is possible to do with

if let delegate = UIApplication.shared.connectedScenes.first?.delegate as? Your_SceneDelegate_Class {
    // ... access anything needed in delegate
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM