在 2023 年 6 月 6 日的 WWDC 23 上 Apple 推出了 Xcode 15,相比较 Xcode 14,它有如下变化。
项目
iOS 17.0 Not Install
,平台不同提示略有不同。主界面.png
Storage
选项,不再有Use Core Data
选项。创建项目
导航区
调试区
Archive.png
Image Set
与Color Set
可以生成类型安全的标识符,在程序中可以.标识符
的形式访问。// UIKit
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIColor(resource: .colorSet)
UIImage(resource: .imageSet)
}
}
// SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Color(.colorSet) // Color Set
Image(.imageSet) // Image Set,只是新建不行,还必须有图片
}
.padding()
}
}
// UIKit
public macro Preview(_ name: String? = nil,
traits: PreviewTrait<Preview.ViewTraits>...,
body: @escaping () -> UIView) -> () = #externalMacro(module: "PreviewsMacros", type: "Common")
public macro Preview(_ name: String? = nil,
traits: PreviewTrait<Preview.ViewTraits>...,
body: @escaping () -> UIViewController) -> () = #externalMacro(module: "PreviewsMacros", type: "Common")
// 使用
#Preview {
UIKit 预览内容
}
// AppKit
public macro Preview(_ name: String? = nil,
traits: PreviewTrait<Preview.ViewTraits>...,
body: @escaping () -> NSView) -> () = #externalMacro(module: "PreviewsMacros", type: "Common")
public macro Preview(_ name: String? = nil,
traits: PreviewTrait<Preview.ViewTraits>...,
body: @escaping () -> NSViewController) -> () = #externalMacro(module: "PreviewsMacros", type: "Common")
// 使用
#Preview {
AppKit 预览内容
}
image.png
command + shift + A
。