我正在尝试创建一个单一的访问方法。我收到这个错误(见下面的代码)。我不明白为什么我收到这个错误,这个错误是什么意思。有人可以解释吗
@UIApplicationMain class AppDelegate: UIResponder,UIApplicationDelegate { static private var thedelegate: AppDelegate? class var delegate : AppDelegate { return thedelegate! } func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { thedelegate = self // Syntax error: Static member 'thedelegate' cannot be used on instance of type 'AppDelegate'
您正在尝试从该类的实例访问类级别变量。要使用它,您需要使类级别的功能:static func()。尝试这个:
原文链接:https://www.f2er.com/swift/320601.htmlstatic func sharedDelegate() -> AppDelegate {return UIApplication.sharedApplication().delegate as! AppDelegate}