我们之前创建好的 App 是 Tuist 为我们准备的初始内容,是一个简单的 SwiftUI 项目,但是,我们本书的项目刻意选择了继续使用 UIKit 而不是 SwiftUI,因此我们需要用 UIKit 将这个项目重写。
为了简单起见,我们先删除 ContentView.swift,直接利用如下内容覆盖 NovarApp.swift
import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { let window = UIWindow(frame: UIScreen.main.bounds) let vc = UIViewController() vc.view.backgroundColor = .white let label = UILabel() label.text = "Hello, World!" label.textColor = .black label.translatesAutoresizingMaskIntoConstraints = false vc.view.addSubview(label) NSLayoutConstraint.activate([ label.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor), label.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor), ]) window.rootViewController = vc window.makeKeyAndVisible() self.window = window return true } }
写 scene 相关的内容,并链过去