加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 05:55:54 所属栏目:百科 来源:网络整理
导读:我正在尝试创建一个单一的访问方法。我收到这个错误(见下面的代码)。我不明白为什么我收到这个错误,这个错误是什么意思。有人可以解释吗 @UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate { static private var thedelegate: AppDe
我正在尝试创建一个单一的访问方法。我收到这个错误(见下面的代码)。我不明白为什么我收到这个错误,这个错误是什么意思。有人可以解释吗
@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()。尝试这个:
static func sharedDelegate() -> AppDelegate {return UIApplication.sharedApplication().delegate as! AppDelegate}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读