简体   繁体   English

如何从 NSObject 访问 SceneDelegate?

[英]How to access SceneDelegate from NSObject?

I declared a variable in sceneDelegate and want to access that variable from the NSObject.我在 sceneDelegate 中声明了一个变量,并希望从 NSObject 访问该变量。 We can do that from UIView or UIViewController, but don't know how to do this in NSObject.我们可以从 UIView 或 UIViewController 中做到这一点,但不知道如何在 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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