Weekly Comment
Integrating AI into the Daily Workflow
Large language models have become indispensable assistants in my day-to-day work and personal life. Currently, my primary means of interacting with them is conversational. While this style of communication has grown increasingly smooth and intuitive with the improvement of model capabilities, when various needs are interwoven into a single conversation, the resulting efficiency often falls short of what I’d like. To address this, I’ve recently begun exploring how to tailor prompts for dedicated sessions focused on specific tasks.
In doing so, I have not opted for the popular AI agent-building platforms, but rather relied on the MyGPT functionality offered by ChatGPT. Although I possess some programming experience—for instance, breaking complex tasks into simple modules (like functions)—I still face many challenges when transferring this approach to AI tasks. Figuring out how to effectively decompose tasks and ensure each module produces stable, accurate results isn’t as straightforward as writing code. One might say the abstract reasoning required by large language models differs substantially from the logic of traditional programming. Without a deeper grasp of prompt engineering and the inner workings of these models, even designing a small AI tool that yields consistent, accurate outputs can prove quite daunting. In my view, creating a set of efficient, reliable AI mini-tools for work and personal life remains an ongoing endeavor that calls for further exploration.
Fortunately, as M4 devices become more widespread and other efficient local AI inference solutions emerge, the cost of fine-tuning and customizing smaller models is rapidly declining. If specialized models can be combined with carefully optimized prompts, personal AI tool development will likely witness a significant breakthrough, with notable improvements in both performance and reliability.
I look forward to the day, in the not-so-distant future, when these stable and reliable AI mini-tools can seamlessly integrate into my daily routines—much like the small programs I write for myself—serving as even more capable helpers that enhance both efficiency and user experience.
Previous Issue|Newsletter Archive
If you appreciate my work and want to promote your product to the Swift and iOS developer community, sponsoring my platform could be an excellent opportunity for you.
Your support through Patreon, or Buy Me a Coffee helps keep this newsletter and blog running. Thank you for finding this content helpful!
Recent Selections
How SwiftUI Preview Works Under the Hood
Starting with Xcode 16, the working mechanism of SwiftUI Preview has undergone significant changes, with the most notable improvement being the shared build artifacts between Build/Run and Preview, which enhances Preview's build efficiency. In this article, Onee delves into the inner workings of Preview in Xcode 16, providing a detailed analysis of how Preview utilizes a three-tiered rebuild strategy to handle different levels of code modifications efficiently. The article concludes with a comparison between SwiftUI Preview and Flutter’s Hot Reload, highlighting the current limitations of SwiftUI Preview and potential areas for improvement.
Adopting Swift 6 Across the App Codebase
Swift 6 mode introduces powerful data race detection capabilities but also sets higher standards for code quality. In this article, Majid Jabrayilov shares his practical tips and insights, including how to efficiently use Sendable
value types, when to isolate reference types with @MainActor
, and how to gracefully manage stateful services using actor
. The article provides real-world code examples, offering actionable guidance for concurrent programming with Swift 6.
Codable Conformance for Swift Enums
Since Swift 5.5, enums can automatically conform to Codable
even without raw values, greatly improving development efficiency. However, in many cases, developers still need to customize the encoding and decoding process to meet specific requirements. In this article, Natalia Panferova shares various customization techniques for Codable
enums, including adjusting case names, associated value keys, and implementing fully custom logic. These techniques offer flexibility for API interactions and data persistence.
Swift 6: Typed Throws
Among the many new features in Swift 6, Typed Throws stands out as a highlight. It allows developers to explicitly specify the error types that functions can throw, significantly improving readability and precision in error handling. While this feature may add some upfront effort, its advantages become evident when calling APIs built with Typed Throws. In this article, Vera Dias provides clear examples and demonstrates how this feature simplifies error handling logic and reduces dependency on generic error catches.
Creating a Debounced Search Context for Performant SwiftUI Searches
In SwiftUI, the searchable
modifier makes it easy to implement search functionality, but frequent input can lead to unnecessary search requests and performance issues. Daniel Saidi shares his solution: a reusable search context class combined with debounce techniques, delaying search operations until typing pauses. This approach enhances app responsiveness while significantly reducing redundant operations.
SwiftData CRUD Operations with ModelActor
SwiftData's @ModelActor
provides a safer concurrency experience, but it also poses new challenges for implementing CRUD operations. Leo Dion shares a well-designed and robust API in this article. By introducing the Queryable
protocol and type-safe Selector
, he simplifies CRUD operation logic and enhances reliability. Additionally, the author highlights the issue of temporary PersistentIdentifiers, reminding developers not to use temporary IDs across contexts.
Implementing iCloud Sync with SwiftData and CKSyncEngine
CKSyncEngine, introduced at WWDC 2023, significantly reduces the complexity of CloudKit data synchronization. While Core Data and SwiftData offer built-in CloudKit sync support, their high level of automation makes it difficult to finely control the sync process. In this article, Yingjie Zhao details how to combine CKSyncEngine with SwiftData to build a more flexible iCloud sync solution. By customizing the sync manager, implementing incremental sync, and handling server changes and errors, the author demonstrates a balanced approach between automation and manual control, providing valuable guidance for creating efficient and reliable sync systems.
While the default sync features of Core Data and SwiftData are more comprehensive and generalized (e.g., addressing CloudKit’s limitations on relationship count and record size), CKSyncEngine’s customizability allows for greater flexibility and a more tailored user experience in specific scenarios.
The Swift Runtime: Your Silent Partner
The Swift Runtime (libswiftCore) is a C++ library that runs alongside all Swift programs, supporting core language features such as memory management, error handling, dynamic dispatch, and the handling of types and generics. Jacob Bartlett starts with a simple piece of Swift code and traces its journey from compilation to execution, including Swift Intermediate Language (SIL), LLVM Intermediate Representation (IR), and runtime ABI function calls. He provides an in-depth analysis of how the Swift Runtime operates and collaborates with the compiler to implement essential language features.
肘子的话
将 AI 整合至日常工具链
大语言模型已然成为我日常工作和生活中不可或缺的得力助手。目前,我主要通过对话方式与它互动。虽然随着模型能力的提升,这种交流方式越发流畅自然,但当各类需求混杂在同一会话中时,效率往往难以达到理想状态。为此,我在过去几周开始尝试运用提示词来定制一些面向特定任务的专用会话。
在这个过程中,我没有选择使用流行的 AI 智能体构建工具,而是依托 ChatGPT 提供的 MyGPT 功能展开尝试。虽然具备一定的编程经验,了解如何将复杂任务分解为简单模块(例如函数),但将这种分解思维迁移到 AI 任务中时,我仍面临诸多挑战。如何有效划分任务、确保每个模块输出稳定且符合预期,这些工作并不像编写代码那样直观。可以说,基于大模型的抽象思维与传统编程中的抽象逻辑有着本质区别。在对提示词优化和大模型工作原理理解尚浅的情况下,即便是设计一个简单的 AI 工具,要想生成稳定、准确的结果也绝非易事。对我而言,为工作和生活中打造一系列高效、可靠的 AI 小工具,仍是一个需要持续探索的课题。
值得期待的是,随着 M4 等高性能设备的普及,以及其他高效 AI 本地推理设备的问世,微调和定制小型模型的成本正在快速下降。若能将专属模型与经过针对性优化的提示词相结合,个人化需求的 AI 小工具开发必将迎来显著突破,性能、稳定性表现也会得到更好的保证。
我期待在不久的将来,这些稳定可靠的 AI 小工具能够如同我为自己编写的日常小程序一般,自然地融入工作与生活流程中,成为更加得心应手的助手,让效率和体验同步提升。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
近期推荐
探究 SwiftUI Preview 的工作原理
从 Xcode 16 开始,SwiftUI Preview 的工作机制发生了重要变化,其中最显著的改进是:Build and Run 与 Preview 共享同样的构建产物,从而提升了 Preview 的构建效率。御姐 (Onee) 在本文中,深入探讨了 Xcode 16 下 Preview 的工作原理,详细分析了在项目代码不同程度修改的情况下,Preview 如何通过三层重构策略应对变化以提高效率。文章最后还对 SwiftUI Preview 和 Flutter 的 Hot Reload 进行了对比,指出了目前 SwiftUI Preview 机制的不足和改进潜力。
全面升级 Swift 6:应用代码库的迁移指南 (Adopting Swift 6 Across the App Codebase)
Swift 6 模式带来了强大的数据竞争检查能力,但对开发者也提出了更高的代码质量要求。Majid Jabrayilov 在本文中结合实际项目,分享了他的经验和实用技巧:如何高效利用 Sendable
值类型、何时将引用类型隔离在 @MainActor
中,以及如何通过 actor
优雅地管理有状态的服务类型。文章通过接近实际项目的代码示例,为 Swift 6 并发编程提供了切实可行的指导。
Swift 枚举的 Codable 支持 (Codable Conformance for Swift Enums)
从 Swift 5.5 开始,即使枚举没有设定 Raw 值,只要声明 Codable
,编译器即可自动生成编解码逻辑,大幅提升开发效率。但在许多场景下,开发者仍需要自定义编解码过程以满足特定需求。在这篇文章中,Natalia Panferova 分享了枚举 Codable
的多种自定义技巧,包括调整枚举项名称、关联参数名称以及实现完全自定义逻辑,帮助开发者在与 API 交互或数据持久化时更灵活地处理复杂需求。
Swift 6:类型化抛出 (Swift 6: Typed Throws)
在 Swift 6 的诸多新特性中,类型化抛出(Typed Throws)无疑是其中的亮点之一。它允许开发者在函数中显式指定可能抛出的错误类型,大幅提升了错误处理的可读性和精确性。尽管这一特性可能增加一些前期工作,但在调用基于类型化抛出构建的 API 时,其优势立刻显现。Vera Dias 在本文中通过清晰的图文示例,详细介绍了类型化抛出的使用方法,展示了它如何帮助开发者简化错误处理逻辑,并降低对通用错误捕获的依赖。
在 SwiftUI 中实现去抖搜索 (Creating a Debounced Search Context for Performant SwiftUI Searches)
在 SwiftUI 中,searchable
修饰器让搜索功能变得简单易用,但频繁的输入会导致不必要的检索请求或性能消耗。Daniel Saidi 分享了他解决方案:通过创建可复用的搜索上下文类,结合 Debounce 技术,将查询操作延迟到输入暂停后再执行。这种方法不仅提升了应用的响应速度,还显著减少了多余的操作。
使用 ModelActor 实现 SwiftData 的 CRUD 操作 (SwiftData CRUD Operations with ModelActor)
SwiftData 的 @ModelActor
提供了更加安全的并发操作体验,但也对 CRUD 操作的实现提出了全新的要求。Leo Dion 在本文中分享了一套设计优雅且功能强大的 API,通过引入 Queryable
协议和类型安全的 Selector
,极大地简化了 CRUD 操作的代码,并增强了操作的可靠性。此外,作者特别警示了 PersistentIdentifier 的临时状态问题,提醒开发者不要对临时 ID 进行跨上下文传递。
SwiftData 结合 CKSyncEngine 实现 iCloud 同步
CKSyncEngine 是苹果在 WWDC 2023 推出的框架,大幅降低了开发 CloudKit 数据同步的复杂性。虽然 Core Data 和 SwiftData 提供了内置的 CloudKit 同步支持,但其高度自动化让开发者难以对同步过程进行细粒度控制。赵英杰 (Yingjie Zhao) 在本文中详细介绍了如何结合 CKSyncEngine 和 SwiftData 构建更加灵活的 iCloud 同步方案。通过自定义同步管理器、实现增量同步、处理服务器变更及错误,作者展示了一种平衡自动化与手动控制的同步实现方式,为构建高效、可靠的同步系统提供了参考。
尽管 Core Data 和 SwiftData 的默认同步功能更全面、更通用( 例如妥善解决了 CloudKit 关系数量和记录尺寸的限制 ),但在特定场景下,借助 CKSyncEngine 的自定义能力,可以带来更高的灵活性和更独特的用户体验。
🪜 Swift运行时:你的无声伙伴 (The Swift Runtime: Your Silent Partner)
Swift 运行时(libswiftCore)是一个与所有 Swift 程序同时运行的 C++ 库,为语言的核心功能提供支持,例如内存管理、错误处理、动态派发以及类型和泛型的处理。Jacob Bartlett 从一段简单的 Swift 代码出发,追踪其从编译到执行的全过程,包括 Swift 中间语言(SIL)、LLVM 中间表示(IR),以及运行时 ABI 函数调用,深入解析 Swift 运行时的操作机制及其如何与编译器协作完成核心语言特性的实现。
活动
Swift Student Challenge 将于 2 月 3 日开放申请
Swift Student Challenge 为学生开发者提供了展现自身创造力和编程能力的机会。通过使用 Swift Playgrounds 构建并提交项目,学生能够培养将来可在职业生涯中运用的实际技能,同时成为活跃开发者社区中的一员。
挑战赛提交作品的通道将于 2 月 3 日开始,持续开放三周。抓紧时机,马上开始头脑风暴,并为你的奇思妙进行构建吧。获奖者将获得特别礼物,并有机会在明年夏天到访苹果的库比提诺园区。
The link for the English article "Implementing iCloud Sync with SwiftData and CKSyncEngine" appears in Chinese. This happens in almost all newsletters at least once for an English article. The Chinese article displays in Safari where I can usually have Safari translate it to English; not this time. Please verify all English links in a weekly display English. Thanks.
I consider your weekly newsletter one of the best available. Always full of links to useful articles, including those by yourself. Yours effort is appreciated.