Weekly Comment
Making Swift Stronger, Keeping It Simple
Two years ago, a friend asked me for a programming language recommendation for his six-year-old who was showing interest in coding. Considering he already had an iPad and MacBook, I didn't hesitate to recommend Swift Playgrounds. A few days ago, another friend asked me a similar question, and while I still recommended Playgrounds, I wasn’t as certain as I was two years ago. I’m just not so sure about whether Swift is still suitable for beginners these days.
This year has perhaps been a bit turbulent for many Swift developers. With the arrival of Swift 6, we've had to face an increasing number of compilation warnings. While the intention of preventing data races at the compilation level is good, Swift 6’s “concurrency-first” principle has made coding in some simple scenarios feel restrictive and a bit inconvenient.
Fortunately, the Swift community seems to have taken note of the developers’ feedback. A few days ago, the Swift Language Steering Group (LSG) released their main focus areas for 2025. Among these, the top priority is “making Swift Concurrency easier to approach and adopt.” This is undoubtedly encouraging news.
In a vision document published in November, the development team proposed an idea: allowing developers to choose to compile with default MainActor isolation on a per-module basis. This would create a "single-threaded mode", thereby resolving some of the false positives caused by Swift 6's concurrency safety checks. This move will undoubtedly greatly improve the development experience, reducing unnecessary hassles in non-concurrent scenarios.
The Swift language is gradually becoming more complex, which is almost an inevitable trend for every ambitious language that has developed over time. But this complexity should only increase the ceiling of a programming language's capabilities. Once such complexity impacts the language’s learning curve, it will shake the very foundation of the language.
I sincerely hope that while Swift continues to raise its upper limits, it can also maintain its beginner-friendliness and even further reduce its entry barrier. After all, a good programming language should not only solve complex problems but also make it easy for beginners to get started.
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!
Originals
Model Inheritance in Core Data
One of Core Data’s outstanding features is its ability to allow developers to declare data models in a manner closer to object-oriented programming without worrying about the underlying storage implementation details. Within this framework, model inheritance is a particularly important mechanism. This article delves into the core concepts of model inheritance, including Parent Entity, Sub Entity, and Abstract Entity. We will analyze their advantages and disadvantages and explore how to achieve similar effects without directly using these features.
The inspiration for writing this article came from my recent research into the use of Core Data in Apple's first-party apps, particularly their practices in data model construction. To my surprise, the frequency and depth of model inheritance usage in these apps exceeded my expectations, which motivated me to further explore the application scenarios and advantages of this mechanism.
Recent Selections
Apple’s Use of Swift and SwiftUI in iOS 18
As always, Alexandre Colucci has delivered a comprehensive analysis of the programming languages and UI frameworks used in iOS 18's built-in apps at the end of 2024. The article presents clear data showcasing the ongoing growth of Swift and SwiftUI within Apple’s ecosystem.
While SwiftUI's adoption continues to expand steadily, its growth rate has slowed in recent system versions. To play a larger role in the future, further enhancements in functionality and stability are needed.
SF Symbol: How to for Swift & SwiftUI
SF Symbols, Apple's high-quality, unified icon library, greatly simplifies icon design challenges, especially for indie developers and small teams. Antoine van der Lee provides a comprehensive guide on using SF Symbols, covering tips, animation techniques, customization options, and licensing restrictions, offering developers an excellent resource to master SF Symbols.
Why is Flow Control Important?
Combine offers several operators related to flow control (backpressure), but Swift’s new concurrency model currently lacks sufficient backpressure APIs for AsyncSequence
. In this post, Quinn explores effective data flow management for AsyncSequence
, addressing potential memory issues caused by excessive data production speed. He also highlights a proposed Swift community solution: MultiProducerSingleConsumerChannel, a promising tool to enhance flow control capabilities.
Mocking a Network Connection in Your Swift Tests
Mocking network connections helps avoid external dependencies (e.g., network fluctuations or server downtime), ensuring tests are repeatable, independent, and support parallel execution. Donny Wals discusses two common mocking methods: Mocking the network layer, which isolates dependencies for testing business logic, and URLProtocol, which provides fine-grained control over network implementations for complex interaction validation. These complementary methods equip developers with effective tools for building reliable tests.
Bringing Image Playground to Your App
As part of Apple Intelligence, Image Playground empowers users to create unique and engaging images directly on their devices. Antonella Giugliano provides a detailed guide on seamlessly integrating this feature into SwiftUI and UIKit apps, enabling developers to leverage Apple Intelligence models for quick and creative image generation.
Swift Macro Series
The power of Swift Macros lies in their reliance on the SwiftSyntax library, offering precise control over source code. Kingnight delves deeply into macro basics and practical operations in this series, guiding readers through manipulating abstract syntax trees (AST) to achieve powerful code generation. This series provides a systematic and in-depth analysis of macro implementation and techniques, making it an invaluable reference for mastering Swift Macros.
Exploring MLX Swift: Adding On-Device Inference to Your App
MLX is a machine learning framework optimized for Apple Silicon, enabling large language models (LLMs) to run on-device, enhancing privacy and supporting offline usage scenarios. Rudrank Riyam provides a detailed walkthrough of integrating LLM inference into iOS apps using the MLX Swift framework. Through a SwiftUI example, the article demonstrates the entire process—from model loading to text generation—offering a clear guide for developers to get started quickly.
肘子的话
让 Swift 更强,也更简单
两年前,一位朋友问我,他六岁的孩子对编程产生了兴趣,有什么编程语言可以推荐。考虑到他已经有了 iPad 和 MacBook,我毫不犹豫地推荐了 Swift Playgrounds。几天前,另一位朋友也咨询了类似的问题,尽管我仍然推荐 Playgrounds,但远没有两年前那样坚决。因为如今的 Swift 是否还适合初学者,我有些不确定了。
今年对于许多 Swift 开发者来说,或许都算不上平静。随着 Swift 6 的到来,我们不得不面对越来越多的编译警告。尽管从编译层面防止数据竞争的初衷是好的,但 Swift 6 的“并发优先”原则,却让一些简单场景下的代码编写也变得束手束脚,多少有些不便。
好在 Swift 社区注意到了开发者的反馈。几天前,Swift 语言指导小组(Language Steering Group, LSG))发布了他们在 2025 年的主要关注领域。其中,首要项目便是 “使 Swift 并发更易于上手和采用”。这无疑是令人欣慰的。
在 11 月发表的愿景中,开发团队提出了一个构想:允许开发者以模块为单位,选择默认以 MainActor 隔离的方式进行编译。这将创建一种 “单线程模式”,从而消除一些由 Swift 6 并发安全检查引起的警告。这一举措,无疑能极大地改善开发体验,减少非并发场景下的不必要困扰。
Swift 语言逐渐走向复杂化,这几乎是每一个发展到一定阶段、并且具有雄心的语言的必然趋势。不过一旦这种复杂化影响了语言的易学性,动摇的将是这门语言的根基。
真心希望 Swift 能在不断提高自身上限的同时,也能始终保持对初学者的友好,甚至能够进一步降低入门的难度。毕竟,一门好的编程语言,既要能解决复杂的问题,也应该能够让初学者轻松入门。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
Core Data 的模型继承
Core Data 的一个卓越特点是让开发者能够以更加接近面向对象编程的方式声明数据模型,同时无需关心底层的存储实现细节。在这个框架中,模型继承是一个尤为重要的机制。本文将深入探讨模型继承的核心概念,包括父实体(Parent Entity)、子实体(Sub Entity)和抽象实体(Abstract Entity);我们将分析它们的优缺点,并探讨在不直接使用这些功能时如何实现类似的效果。
写这篇文章的灵感源自我最近对苹果第一方应用中 Core Data 使用情况的研究,尤其是它们在数据模型构建中的实践。让我意外的是,模型继承在这些应用中的使用频次和深度都超出了我的预期,这也激发了我进一步探讨这一机制的应用场景与优势。
近期推荐
Apple 在 iOS 18 中对 Swift 和 SwiftUI 的应用 (Apple’s Use of Swift and SwiftUI in iOS 18)
一如既往的精彩,Alexandre Colucci 在 2024 年底再次为开发者带来了对 iOS 18 内置应用编程语言和 UI 框架使用情况的详尽分析。文章中的数据清晰展现了 Swift 和 SwiftUI 在苹果生态系统中的持续增长趋势。
尽管 SwiftUI 的份额仍在稳步扩大,但其增速在最近几个系统版本中已呈放缓趋势。如果希望 SwiftUI 在未来承担更大的角色,还需要在功能和稳定性上做进一步提升。
SF Symbol:在 Swift 和 SwiftUI 中的使用指南 (SF Symbol: How to for Swift & SwiftUI)
SF Symbols 是苹果为开发者提供的一套高质量、统一的图标库,大大简化了图标设计的难题,尤其对独立开发者和小型团队而言意义非凡。Antoine van der Lee 在这篇文章中全面梳理了 SF Symbols 的使用技巧、动画效果、自定义方法及版权限制等重要内容,为开发者提供了一份了解和使用 SF Symbols 的优质指南。
为什么流量控制很重要?(Why is Flow Control Important?)
Combine 提供了许多与流量控制(背压)相关的操作符,但 Swift 的新并发模型目前尚未为 AsyncSequence 提供足够数量的背压 API。在这篇帖子中,Quinn 探讨了在使用 AsyncSequence
时,如何在数据发送和接收端有效管理数据流,以避免因数据生产速度过快而引发的内存问题。同时,他还提到 Swift 社区正在讨论的一种增强流量控制的方案:MultiProducerSingleConsumerChannel,为开发者提供了更强大的工具来管理数据流。
在 Swift 测试中模拟网络连接 (Mocking a Network Connection in Your Swift Tests)
通过模拟网络,可以有效避免外部依赖(如网络波动或服务器中断)对测试结果的影响,确保测试可重复运行、相互独立并支持并行执行。Donny Wals 在这篇文章中探讨了两种常见的模拟方法:Mock 网络层和 URLProtocol。Mock 网络层通过协议和 Mock 对象隔离依赖,适合专注于测试业务逻辑;而 URLProtocol 提供对网络实现的精细控制,通过拦截网络请求验证请求内容和模拟响应,特别适合复杂网络交互的验证。这两种方法灵活互补,为开发者提供了高效构建可靠测试的工具和思路。
将 Image Playground 集成到你的应用中 (Bringing Image Playground to Your App)
作为 Apple Intelligence 的一部分,Image Playground 使用户能够直接在设备端生成有趣且独特的图像。Antonella Giugliano 在文章中详细介绍了如何将这一功能无缝集成到 SwiftUI 和 UIKit 应用中,帮助开发者充分利用 Apple Intelligence 模型,快速实现图像生成功能,为应用注入更多创意和表现力。
Swift Macro 系列
Swift Macro 的强大之处在于其依托 SwiftSyntax 库,提供了对源代码的精确控制力。Kingnight 在这一系列文章中,通过深入讲解宏的基础概念和实践操作,带领读者了解如何操控抽象语法树(AST)实现强大的代码生成功能。该系列文章对 Swift 宏的实现原理和使用技巧进行了系统和深入的剖析,是开发者深入学习和掌握 Swift 宏技术的重要参考。
探索 MLX Swift:将设备端推理集成到你的应用中 (Exploring MLX Swift: Adding On-Device Inference to your App)
MLX 是一个专为 Apple Silicon 优化的机器学习框架,支持大语言模型 (LLMs) 在设备端运行,从而增强隐私保护并支持离线使用场景。Rudrank Riyam 在文中详细讲解了如何通过 MLX Swift 框架,将 LLM 推理功能集成到 iOS 应用中。他通过一个 SwiftUI 示例,从模型加载到文本生成,完整演示了实现过程,为开发者快速上手提供了清晰的指导。
活动
展望未来:打造出色的 visionOS App (线下)
1月8日上午10:00-下午5:00
参加在上海 Apple 开发者中心举办的为期一天活动,了解如何打造出色的 visionOS App。 你将通过三个讲座学习如何开始使用 SwiftUI,探索一流的 App,并深入了解 RealityKit 和 Reality Composer Pro。随后,你还将听取开发者社区成员的分享,并有机会体验一系列 visionOS App 示例。
线下与会者将可享用午餐。请注意,此活动的名额有限。活动语言为普通话。
活动安排
上午 10:00 讲座:从 SwiftUI 入手
上午 11:00 讲座:构建 3D 沉浸式内容
中午 12:00:午餐
下午 1:00 讲座:结合 SwiftUI 和 RealityKit 的强大功能
下午 2:00:开发者案例学习与演示下午 4:00 – 5:00:visionOS App 体验与讨论
请在 12 月 26 日晚上 11:45 (GMT+8) 之前提交申请。
I appreciate your blog and look forward to it. I hesitate to offer feedback, but I will today. You posted a link to an article today “Bringing Image Playground to Your App” that resolves to X.
I, and I assume other readers of yours, have disassociated from X. I found a direct link to her article at https://www.createwithswift.com/bringing-image-playground-to-your-app/.
It might be helpful in future posts to share the direct article link rather than a passthrough via X.
Thanks for considering this. And… thanks for your writing. Cheers!