Weekly Comment
Happy New Year 2025
Despite the unrest in the world, 2024 has been a fulfilling and wonderful year for me. Throughout the year, I wrote 47 articles and published 51 weekly newsletters, and I can feel my understanding of Swift and SwiftUI continuously deepening. What brings me the most joy is that my entire family has stayed healthy and well.
I wish everyone good health and happiness in 2025. I also look forward to seeing Swift and SwiftUI continue to flourish in the new year.
Happy New Year 2025! 🎉
Previous Issue|Newsletter Archive
Originals
Why Certain View Modifiers in Swift 6 Cannot Use the @State Property
In Xcode 16, to improve SwiftUI’s performance under Swift 6 mode, Apple made several adjustments to the SwiftUI framework’s APIs to meet stricter concurrency checks. The most notable change is the comprehensive annotation of the View
protocol with @MainActor
. While these optimizations generally enhance the developer experience in Swift 6 mode, they also introduce some seemingly anomalous compile-time errors in specific scenarios. This article delves into why certain view modifiers cannot directly use @State
properties and provides corresponding solutions.
This is my last article published in 2024. I will be taking a break and plan to resume publishing new articles after the Spring Festival, around mid-February 2025. During this period, the weekly newsletter will continue to be published as usual.
Recent Selections
Exploring TabView Advancements in SwiftUI
At WWDC 2024, TabView
received a major upgrade, streamlining the development process and bringing unprecedented flexibility and expressiveness to iPadOS and macOS platforms. This update introduced several remarkable new features, including a simplified tab creation method, enhanced programmatic navigation capabilities, and the sidebarAdaptable
style optimized specifically for iPadOS. To fully understand these groundbreaking changes, Gabriel Theodoropoulos has written two in-depth articles that comprehensively showcase the evolution and improvements of TabView
.
Reading and Displaying Genmoji in Non-Rich Text Formatted Data Context
Genmoji, an innovative feature launched by Apple at WWDC 2024, cleverly combines "generative" and "emoji" technology, enabling users to easily create unique personalized emojis. Based on NSAdaptiveImageGlyph
, the feature is naturally suited for rich-text environments. In this article, Antonella Giugliano explains how to use SwiftUI to render information extracted from NSAdaptiveImageGlyph
, enabling the display of Genmoji in non-rich text environments. This method provides developers with a flexible solution for handling and displaying mixed-content text and images.
Crafting a Dissolve Effect in Metal and SwiftUI
Metal’s shader system provides developers with powerful tools for creating high-performance, visually stunning effects. In this article, Uladzislau Volchyk explores how to use Metal to implement a dissolve effect, with a focus on the fundamentals of the Metal rendering pipeline. The author uses several diagrams to explain the working principles in detail, while providing complete implementation code, covering key steps such as renderer configuration, writing vertex and fragment shaders, and building the rendering pipeline with enabled blending functionality.
Write Swift Like Apple
There are many different code conventions in the Swift programming language. In his years of development experience, Uwais Alqadri found that when working with projects combining UIKit and SwiftUI, the best practice is to follow Apple’s own Swift coding style. Through two articles, he summarizes some of the common practices in Apple’s Swift programming, focusing on sensible naming, concise type inference, and clear protocol design, which allows the code to remain elegant and simple while naturally fitting into Apple’s framework design philosophy.
MyTallies Widgets, AppIntents, Siri Shortcuts and WatchKit
In this tutorial series, Stewart Lynch uses a SwiftUI and SwiftData-based counter app, MyTallies, to demonstrate how to build cross-platform functionality within the Apple ecosystem. The tutorial provides a comprehensive guide to developing widgets, implementing AppIntents, integrating Siri Shortcuts, and building WatchKit applications for the Apple Watch, offering clear explanations of these core technologies.
肘子的话
2025 新年快乐
尽管世界局势并不平静,2024 对我而言却是一个充实美好的年份。这一年里,我写下了 47 篇文章,发布了 51 期周报,也能感受到自己对 Swift、SwiftUI 的理解在不断深入。而最令我欣慰的,是全家人都健康平安。
祝愿大家在 2025 年都能拥有健康的身体、愉悦的心情。也期待 Swift、SwiftUI 在新的一年里继续蓬勃发展。
2025 新年快乐!🎉
原创
为何 Swift 6 中某些视图修饰器无法使用 @State 属性
在 Xcode 16 中,为了改善 SwiftUI 在 Swift 6 模式下的表现,苹果对 SwiftUI 框架的 API 进行了多项调整,以满足更严格的并发检查要求。其中最显著的变化是将 View
协议全面标注为 @MainActor
。这些优化虽然总体上改善了开发者在 Swift 6 模式下的编程体验,但也在某些特定场景中引发了一些看似反常的编译错误。本文将详细探讨为什么某些视图修饰器中无法直接使用 @State
属性值,并提供相应的解决方案。
本文是我在 2024 年发表的最后一篇文章。接下来,我将休息一段时间,计划于春节过后( 2025 年 2 月中旬)恢复发布新文章。在此期间,周报仍将正常发布。
近期推荐
探索 SwiftUI 中 TabView 的进展 (Exploring TabView Advancements in SwiftUI)
在 WWDC 2024 上,TabView
迎来了重大升级,不仅简化了开发流程,更为 iPadOS 和 macOS 平台带来了前所未有的灵活性与表现力。此次更新带来了多项引人瞩目的新特性,包括更为简洁的标签页创建方式、增强的程序化导航能力,以及专为 iPadOS 优化的 sidebarAdaptable
样式等。为深入理解这些革新性的变化,Gabriel Theodoropoulos 撰写了两篇深度解析文章,全面展示了 TabView
的演进与提升。
在非富文本环境中解析与展示 Genmoji (Reading and Displaying Genmoji in Non-Rich Text Formatted Data Context)
Genmoji 作为苹果公司在 WWDC 2024 重磅推出的创新功能,巧妙地融合了"生成式"(Generative)和"表情符号"(Emoji)技术,让用户能够轻松创建独具特色的个性化表情。该功能基于 NSAdaptiveImageGlyph
实现,天然适配富文本环境。在本文中,Antonella Giugliano 介绍了如何利用 SwiftUI 来渲染从 NSAdaptiveImageGlyph
中提取的信息,从而在非富文本环境下展示 Genmoji。这一方法为开发者提供了一种灵活的解决方案,用于处理和展示图文混合内容。
在 Metal 和 SwiftUI 中创建溶解效果 (Crafting a Dissolve Effect in Metal and SwiftUI)
Metal 的着色器系统为开发者提供了创建高性能、视觉炫丽特效的强大工具。在这篇文章中,Uladzislau Volchyk 探讨了如何利用 Metal 实现溶解特效,并重点讲解了 Metal 渲染管线的基础知识。作者通过多张图表详细解释了工作原理,同时提供了完整的实现代码,涵盖了渲染器的配置、顶点与片段着色器的编写,以及启用混合功能的渲染管线构建等关键环节。
像苹果一样写 Swift (Write Swift Like Apple)
Swift 编程语言有许多不同的代码规范。在多年的开发经验中,Uwais Alqadri 发现,混合使用 UIKit 和 SwiftUI 的项目时,最好的做法是遵循苹果自己在 Swift 编程中的编码风格。通过两篇文章,他总结了苹果在 Swift 编程中的一些习惯用法,通过合理命名、简洁的类型推断和清晰的协议设计,让代码既保持优雅简洁,又能自然融入苹果的框架设计理念。
MyTallies Widgets, AppIntents, Siri Shortcuts and WatchKit
在这个系列教程中,Stewart Lynch 以一款基于 SwiftUI 和 SwiftData 开发的计数器应用 MyTallies 为基础,全面展示了如何在苹果生态系统中构建多平台功能。教程深入浅出地讲解了小组件(Widgets)的开发、AppIntents 的应用、Siri 快捷指令的集成,以及 WatchKit 手表应用的构建等核心技术。
Swift 官方编程指南 6.0(中文版)
SwiftGG 翻译小组 已经完成了 Swift 6.0 版本官方文档的翻译工作。欢迎大家订阅他们的微信公众号《SwiftGG 技术小组》,该公众号将定期发布与 Swift 相关的技术内容。
Happy New Year and enjoy ur break! 🎉