如何在swift中使用来自不同类的变量?

如何在swift中使用来自不同类的变量?,swift,variables,Swift,Variables,我想从另一个类中的AppDelegate类访问变量 class AppDelegate: NSObject, NSApplicationDelegate class Other: NSView 我尝试了AppDelegate.variable,但它不起作用您需要这样做:让AppDelegate=UIApplication.sharedApplication().delegate为!AppDelegate,然后您可以访问其成员变量 别忘了添加导入UIKit它说没有这样的模块UIKit。。。也许

我想从另一个类中的AppDelegate类访问变量

class AppDelegate: NSObject, NSApplicationDelegate

class Other: NSView

我尝试了AppDelegate.variable,但它不起作用

您需要这样做:
让AppDelegate=UIApplication.sharedApplication().delegate为!AppDelegate
,然后您可以访问其成员变量

别忘了添加
导入UIKit
它说没有这样的模块UIKit。。。也许是因为这是一个我不知道的mac应用