Weekly Comment
Warning-Free Compilation is Not the Ultimate Goal of Swift 6
Recently, I began refactoring one of my apps, with full Swift 6 support being a key consideration. During this process, I first attempted to achieve perfect compilation for my self-built third-party libraries in Swift 6 mode.
The code in these libraries isn't complex, and after some adjustments, most could compile without warnings in Swift 6 mode. However, this result didn't particularly please me. Reviewing the modified code, I realized that the changes were more about appeasing the compiler rather than approaching concurrency safety challenges from a holistic design perspective with a fresh viewpoint.
Swift 6 attempts to preemptively mitigate risks in complex multi-threaded environments through stricter compiler checks. While the compiler can provide considerable assistance to developers, we shouldn't overly rely on these safety prompts. Instead, we should rethink how to construct code structures that not only meet compilation requirements but are truly safe and reliable, based on a deep understanding of Swift's new concurrency tools.
It's foreseeable that Swift 6 will bring additional troubles and burdens to developers for a considerable period, especially for beginners. As new frameworks and APIs extensively adopt new concurrency tools, Swift language newcomers may face these profound issues too early, potentially affecting Swift's promotion and application.
However, from another perspective, the rapid development of AI has both lowered the entry barrier in certain fields and demanded that developers master more skills and possess the ability to integrate knowledge to avoid being replaced by AI. The challenges brought by Swift 6, to some extent, also build a new line of defense for human developers. After all, for quite some time, AI will still lack excellent abstract thinking and overall planning abilities.
Therefore, to maintain our value in the AI era, we shouldn't set "code compiling without warnings in Swift 6 mode" as our sole goal. Instead, we should view it as an opportunity to deeply understand language evolution, enhance our system design capabilities, and truly master the essence of concurrent programming.
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 to Use EditorConfig Files in Xcode
Developers often encounter different coding styles and conventions when managing multiple projects, necessitating manual adjustments to Xcode's editor settings each time they switch projects. This is not only cumbersome but also prone to inconsistencies in code formatting. To address this issue, Xcode 16 has introduced support for EditorConfig files, allowing developers to programmatically define editor settings for each project. Pol Piella provides a detailed introduction to this new feature in this article and shares how to use EditorConfig in projects.
It's worth noting that in Xcode 16 beta 6, Xcode must be restarted after any modification to the EditorConfig settings for the new configuration to take effect, which is a known bug.
SwiftUI for Mac 2024
In this article, Sarah Reichelt explores some of the new features of SwiftUI in 2024. As the author of the book macOS by Tutorials, Reichelt particularly showcases many new features introduced for macOS at WWDC 2023 and WWDC 2024. The article covers window management, tab syntax updates, preview enhancements, as well as new color mixing and mesh gradient effects. Reichelt argues that after years of development, SwiftUI has increasingly unified code across Apple's platforms, enabling high code sharing across platforms. However, developers still need to consider the characteristics of different platforms during development to ensure that the app's user experience aligns with the platform's design philosophy.
Getting Setup With Xcode Cloud
Xcode Cloud is a Continuous Integration and Continuous Delivery (CI/CD) platform provided by Apple, which simplifies the processes of building, testing, signing, and releasing applications for developers. In this article, Darryl Bayliss thoroughly explains the entire process from setup to workflow management, including creating and configuring workflows, setting triggers, running shell scripts, and viewing workflow results, along with a wealth of practical advice and best practices.
Cross-Platform Swift: WebAssembly
In this article, Brandon Williams and Stephen Celis demonstrate the potential of combining Swift with WebAssembly for cross-platform development. They detail the entire process from setting up the project to interacting with the browser, including how to configure WebAssembly in Xcode, use the JavaScriptKit library to manipulate the DOM, and utilize Swift's Observation framework for data binding. This approach allows developers to build browser applications using familiar Swift code and share the same models and business logic with the iOS platform. This opens up new possibilities for Swift cross-platform development and shows how to build applications for different platforms using a single codebase.
My History with Code Editors: From Syntax Highlighting to AI Generation
This article reviews Baoyu's journey with code editors since 1999, showcasing the evolution from simple text editing to modern AI-assisted code generation. Through personal experience, the author narrates the use of different editing tools at various stages of development and their impact on efficiency. The article traces the progression from basic notepad, through syntax highlighting and intelligent sensing, to today's AI generation, illustrating how editing tools have evolved with technological advances. The author believes that as technology progresses, the improvement of development tools is inevitable. The key is how to use these tools to more efficiently build quality software, rather than fixating on the process of manual coding.
Update: Tips and Considerations for Using Lazy Containers in SwiftUI
Last week, a user reported that the optimization mechanisms of SwiftUI break down when the top-level structure type of a List
's subview is _ConditionalContent
. After testing, I confirmed this issue and have proposed a solution. Details of this phenomenon and relevant considerations have been updated in the current article for developers' reference.
肘子的话
无警告编译并非 Swift 6 的初衷
最近,我着手重构自己的一个 App,其中 Swift 6 的完整支持成为了一个重要考量。在这个过程中,我首先尝试让自己构建的第三方库在 Swift 6 模式下实现完美编译。
这些库的代码并不复杂,经过一番调整,大多数都能在 Swift 6 模式下实现无警告编译。然而,这个结果并没有让我感到特别欣喜。回顾修改过的代码,我意识到所做的改动更像是为了讨好编译器,而非从整体设计的角度出发,用全新的视角来应对并发安全的挑战。
Swift 6 通过更严格的编译器检查,试图在复杂的多线程环境中提前规避风险。虽然编译器能为开发者提供不少帮助,但我们不应过度依赖这些安全提示。相反,我们应该在深入理解 Swift 新并发工具的基础上,重新思考如何构建既符合编译需求又真正安全可靠的代码结构。
可以预见,Swift 6 会在不短的一段时间内会给开发者带来额外的困扰和负担,尤其是对初学者而言。随着新框架和 API 大量采用新的并发工具,Swift 语言的新手可能会过早地面对这些深奥问题,这或许会影响 Swift 的推广和应用。
然而,从另一个角度来看,AI 的快速发展既降低了某些领域的入门门槛,又要求开发者掌握更多技能并具备融会贯通的能力,以免被 AI 取代。Swift 6 带来的挑战,某种程度上也为人类开发者筑起了一道新的防线。毕竟,在相当长的一段时间内,AI 仍难以具备优秀的抽象思维和整体规划能力。
因此,为了在 AI 时代保持自身价值,我们不应将“代码在 Swift 6 模式下无警告编译”作为唯一目标。相反,我们应该将其视为一个契机,去深入理解语言的演进,提升自己的系统设计能力,真正掌握并发编程的精髓。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
近期推荐
如何在 Xcode 中使用 EditorConfig 文件 ( How to use EditorConfig files in Xcode )
开发者在处理多个项目时,往往会遇到不同的编码风格和约定,这使得每次切换项目时都需要手动调整 Xcode 的编辑器设置,这不仅麻烦,还容易出现不一致的代码格式问题。为了解决这个问题,Xcode 16 新增了对 EditorConfig 文件的支持,可以为每个项目以编程方式定义编辑器设置。Pol Piella 在本文中对这个新功能做了详细的介绍,并分享了如何在项目中使用 EditorConfig。
值得注意的是,在 Xcode 16 beta 6 中,每次修改 EditorConfig 配置后,需要重启 Xcode ,新配置才能起作用,这是一个已知 Bug。
SwiftUI for Mac 2024
在本文中,Sarah Reichelt 探讨了 SwiftUI 在 2024 年的一些新特性。作为书籍 macOS by Tutorials 的作者,Reichelt 尤其展示了很多在 WWDC 2023 和 WWDC 2024 中为 macOS 引入的 SwiftUI 新功能。文章涵盖了窗口管理、标签页语法更新、预览功能改进,以及新增的颜色混合与网格渐变效果等内容。作者认为,经过多年发展,SwiftUI 逐渐统一了 Apple 各个平台的代码,实现了跨平台代码的高度共享,但开发者在开发过程中仍需考虑不同平台的特性,以确保应用的用户体验与平台的设计理念相一致。
Xcode Cloud 入门 ( Getting Setup With Xcode Cloud )
Xcode Cloud 是苹果提供的持续集成和持续交付 (CI/CD) 平台,帮助开发者简化构建、测试、签名和发布应用的过程。在本文中,Darryl Bayliss 详细讲解了从设置到工作流管理的整个过程,包括创建和配置工作流、设置触发条件、运行 Shell 脚本,以及查看工作流结果,并提供了大量实用的建议和最佳实践。
跨平台 Swift:WebAssembly ( Cross-Platform Swift: WebAssembly )
在这篇文章中,Brandon Williams 和 Stephen Celis 展示了如何将 Swift 与 WebAssembly 结合,用于跨平台开发。他们详细演示了从设置项目到实现与浏览器交互的整个过程,包括如何在 Xcode 中配置 WebAssembly、使用 JavaScriptKit 库操作 DOM 以及利用 Swift 的 Observation 框架进行数据绑定。通过这种方法,开发者可以用熟悉的 Swift 代码在浏览器中构建应用,并与 iOS 平台共享相同的模型和业务逻辑。这为 Swift 跨平台开发开辟了新的可能性,并展示了如何用一种代码构建面向不同平台的应用。
我的代码编辑器使用史,从语法高亮到 AI 生成
本文回顾了宝玉自 1999 年开始使用代码编辑器的历程,展示了从简单的文本编辑到现代 AI 辅助代码生成的技术演变。通过个人经验,作者讲述了在不同开发阶段中使用的编辑工具及其对开发效率的提升。文章从最初的记事本、语法高亮到智能感知,再到如今的 AI 生成,展现了编辑器工具如何随着技术进步不断演变。作者认为,随着技术的演进,开发工具的改进是不可避免的,重要的是如何借助这些工具更高效地构建优质软件,而不是纠结于手写代码的过程。
更新:几个在 SwiftUI 中使用惰性容器的技巧和注意事项
上周有网友反馈,当 List
中的子视图的顶层结构类型为 _ConditionalContent
时,SwiftUI 的优化机制会失效。经过测试,我确认了这个问题,并提出了解决方案。此现象的具体描述和相关注意事项已经更新至当前文章中,供开发者参考。