swift纯代码新建项目

本文记录使用swift新建一个项目,然后在手机上运行成功就是本文的目的。

大部分的内容参考这篇文章【https://www.cnblogs.com/cchHers/p/15827848.html】,本文主要是做Swift版本的一个补充。

主要的流程依然是:

1、给AppDelegate添加window属性,并初始化window
2、删除掉AppDelegate中的两个关于SceneDelegate的两个协议方法
3、删除掉Info.plist中的Applection Scene Manifest 字段、Main storyboad file base name 字段
4、删除掉SceneDelegate文件、Main.storyboard文件
5、在AppDelegate中把之前的几个代理方法些回来

 

初始化window的代码参考如下:

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        initWindow()
        
        return true
    }
    
    func initWindow() {
        self.window = UIWindow.init()
        self.window?.backgroundColor = .white
        self.window?.frame = UIScreen.main.bounds
        self.window?.makeKeyAndVisible()
        self.window?.rootViewController = ViewController()
    }
}

  

 

posted @ 2022-06-14 16:47  码出境界  阅读(501)  评论(0)    收藏  举报