swift – 静态成员不能在类型的实例上使用

前端之家收集整理的这篇文章主要介绍了swift – 静态成员不能在类型的实例上使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个单一的访问方法。我收到这个错误(见下面的代码)。我不明白为什么我收到这个错误,这个错误是什么意思。有人可以解释吗
@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'
@H_403_4@
您正在尝试从该类的实例访问类级别变量。要使用它,您需要使类级别的功能:static func()。尝试这个:
static func sharedDelegate() -> AppDelegate {return UIApplication.sharedApplication().delegate as! AppDelegate}
原文链接:https://www.f2er.com/swift/320601.html

猜你在找的Swift相关文章