swift 中怎么取得UIApplication的对象实例,并且可以封装成组件不报错

static var mainWindow: UIWindow {

    get {
        let app = UIApplication.shared.delegate as! AppDelegate;
        if app.window != nil {
            app.window!.backgroundColor = .white;
            app.window!.makeKeyAndVisible();
            return app.window!;
        }
        app.window = UIWindow.init(frame: UIScreen.main.bounds);
        app.window?.backgroundColor = .white;
        app.window?.makeKeyAndVisible();
        return app.window!;
    }
    set {
        let app = UIApplication.shared.delegate as! AppDelegate;
        app.window = newValue;

    }
}

拖进项目正产使用,封装报错

  • ERROR | [iOS] xcodebuild: /Users/shang/Documents/GitHub/SwiftExpand/SwiftExpand/UIApplication+Helper.swift:77:57: error: use of undeclared type 'AppDelegate'
阅读 1.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进