How to get an object instance of UIApplication in swift, and it can be encapsulated into a component without reporting errors.

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;

    }
}

drag it into the actual production of the project, encapsulate and report an error

  • ERROR | [iOS] xcodebuild: / Users/shang/Documents/GitHub/SwiftExpand/SwiftExpand/UIApplication+Helper.swift:77:57: error: use of undeclared type "AppDelegate"
Feb.22,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bcb1dc-44fe6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bcb1dc-44fe6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?