戴铭
戴铭
[Link fast: Improve build and launch time](https://developer.apple.com/videos/play/wwdc2022/110362/) 详细讲了 Apple 今年怎么改进了 link,思路很棒,很值得学习。 Static linking 和 Dynamic linking ,也就是静态链接和动态链接。 静态链接就是链接各个编译好的源文件以及链接源文件和编译好的库文件,通过将函数名放到符号表,链接新文件时确定先前是否有包含的 undefined 符号,给函数的数据指令分配地址,最后生成一个有 TEXT、DATA、LINKEDIT 段的可执行文件。 今年 Apple 通过利用多核优势让静态链接快了两倍。 具体做法是,并行的拷贝文件内容。并行构建 LINKEDIT 段的各个不同部分。并行改变 UUID 计算和...
相关提案包括 [SE-0349 Unaligned Loads and Stores from Raw Memory](https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md) 、[SE-0334 Pointer API Usability Improvements](https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md) 、[SE-0333 Expand usability of withMemoryRebound](https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md) Set 使用新的 Temporary Buffers 功能,让 intersect 速度提升了 4 到 6 倍。
session [Debug Swift debugging with LLDB](https://developer.apple.com/videos/play/wwdc2022-110370) 编译器编译 swift 文件生成 `.o` 文件会有 `__debug_info` 段,其中有可以映射到源文件和行号的地址。debug 信息可以链接到 `.dSYM` 包。debug 信息链接器叫 dsymutil,dsymutil 可以为每个动态库、framework 或 dylib 和可执行文件打包一个 debug 信息存档(`.dSYM` 包)。 image 和路径怎么重映射。使用 `image list nameOfFramework`...
现在支持 Swift、OC 和 C,文档标记一样。`.doccarchive` 包含可部署的网站内容,兼容大多数托管服务,比如 Github pages。部署到在线服务上可参考 [Generating Documentation for Hosting Online](https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/generating-documentation-for-hosting-online/) 和 [Publishing to GitHub Pages](https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/publishing-to-github-pages/) 文档。 和 SPM 集成参看 [SwiftDocCPlugin](https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/) 。 session 有 [What’s new in Swift -DocC](https://developer.apple.com/videos/play/wwdc2022-110368)...
actor 具有分布式形式工作能力,也就是可以 RPC 通过网络读取和写入属性或者调用方法。设计为保护在跨多个进程中的低级别数据竞争。Distributed actors 可以在两个进程间建立通道,隔离它们状态,并在它们之间异步通信。每个 distributed actors 在 actor 初始化时分配一个不可以手动创建的 id,在它所属整个 distributed actor 系统中唯一标识所指 actor,这样无论 distributed actors 在哪,都可以以相同的方式与之交互。 session [Meet distributed actors in Swift](https://developer.apple.com/videos/play/wwdc2022/110356/) 。这里有个 distributed actors 的代码示例 [TicTacFish:...
session [Eliminate data races using Swift Concurrency](https://developer.apple.com/videos/play/wwdc2022-110351) 、[Visualize and optimize Swift concurrency](https://developer.apple.com/videos/play/wwdc2022-110350) 、[Meet Swift Async Algorithms](https://developer.apple.com/videos/play/wwdc2022-110355) 。 表示持续时间有了新的放来来表达,对应提案是 [SE-0329 Clock, Instant, and Duration](https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md) ,continuous clock 是在系统睡眠状态还会增加时间,suspending clock 在系统睡眠状态不会增加时间。Instants 表示一个确定的时间。Duration 表示两个时间经历了多久。...
标准库多了个 `Regex` 类型,Regex 语法与 Perl、Python、Ruby、Java、NSRegularExpression 和许多其他语言兼容。可以用 `let regex = try! Regex("a[bc]+")` 或 `let regex = /a[bc]+/` 写法来使用。[SE-0350 Regex Type and Overview](https://github.com/apple/swift-evolution/blob/main/proposals/0350-regex-type-overview.md) 引入 Regex 类型。[SE-0351 Regex builder DSL](https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md) 使用 result builder...
 SwiftUI 里实现动画的方式包括有 .animation 隐式动画、withAnimation 和 withTransaction 显示动画、matchedGeometryEffect Hero 动画和 TimelineView 等。 示例代码如下: ```swift struct PlayAnimation: View { @State private var isChange = false private var anis:[String: Animation] = [...
Canvas 可以画路径、图片和文字、Symbols、可变的图形上下文、使用 CoreGraphics 代码和做动画。 图形上下文可以被 addFilter、clip、clipToLayer、concatenate、rotate、scaleBy、translateBy 这些方法来进行改变。 示例代码如下: ```swift struct PlayCanvas: View { let colors: [Color] = [.purple, .blue, .yellow, .pink] var body: some View { // 画路径 PCCanvasPathView(t: .rounded)...
键盘快捷键的使用方法如下: ```swift struct PlayKeyboard: View { var body: some View { Button(systemIconName: "camera.shutter.button") { print("按了回车键") } .keyboardShortcut(.defaultAction) // 回车 Button("ESC", action: { print("按了 ESC") }) .keyboardShortcut(.cancelAction) // ESC 键 Button("CMD...