Weekly Comment
Apple Vision Pro started shipping to customers a few days ago, with the first batch of deliveries exceeding expectations impressively. Feedback from various quarters indicates that aside from its weight and price, the Apple Vision Pro surpasses its competitors in most aspects of the experience. Numerous users have already showcased videos on social media of using the device in various scenarios such as driving, exercising, walking, and working, hinting at the emergence of a new cyberculture. We look forward to this trend continuing and hope to see breakthrough applications soon that fully leverage the potential of the Apple Vision Pro.
Moreover, last week, Apple also announced the first open-source release of a programming language named Pkl (pronounced as Pickle). Pkl is specifically designed for writing configuration files and is intended to be used as a command-line tool, software library, or build plugin. The developers of Pkl argue that configuration files are best written in a dedicated configuration language, which combines the features of static configuration formats and general-purpose programming languages. Notably, despite being an official Apple release, Pkl is currently implemented in Java and only supports editors like IntelliJ, VSCode, and Neovim. At present, Pkl has provided support libraries for Java, Kotlin, Swift, and Go, meaning iOS developers can now use Pkl language to create configuration files in their Swift projects.
As for why Apple launched this language and the potential scenarios it might be used within Apple's development ecosystem, it's left to the readers' imagination.
With the Spring Festival — China's traditional festival — approaching, I would like to extend my sincerest wishes to all readers in advance: Happy New Year, wishing you and your family happiness, health, and prosperity in the Year of the Dragon!
Next week, I will be celebrating the Spring Festival with my family, so both the newsletter and the blog will be on a break for a week.
Previous Issue|Newsletter Archive
If you find this weekly newsletter or my blog helpful, I would greatly appreciate your consideration of making a donation through Patreon, or Buy Me a Coffee.
Originals
Exploring SwiftUI Property Wrappers: @FetchRequest, @SectionedFetchRequest, @Query, @Namespace, @Bindable
In this article, we will explore property wrappers such as @FetchRequest
, @SectionedFetchRequest
, @Query
, @Namespace
, and @Bindable
. These property wrappers encompass functionalities such as retrieving Core Data and SwiftData within views and creating namespaces in views.
This is the third article in the "Exploring SwiftUI Property Wrappers" series (out of four), where we previously discussed: @State, @Binding, @StateObject, @ObservedObject, @EnvironmentObject, @Environment and @AppStorage, @SceneStorage, @FocusState, @GestureState, @ScaledMetric.
Recent Selections
If you are a developer of Apple Vision Pro, then you must pay attention to these points
Apple Vision Pro has officially hit the market, and many developers will soon (if they haven't already) receive the devices they've ordered. For those of you who are or will soon become developers for Apple Vision Pro applications, what are the key points to keep in mind? This article, co-written by three members of XReality Zone, aims to provide developers with a comprehensive guide to designing and developing applications for Apple Vision Pro. The article covers several core topics, including how to debug the device, how to create App Store videos and screenshots according to Apple's specifications, and how to effectively use various tools and techniques to create high-quality app previews. This guide is designed to help developers fully understand the development details related to Apple Vision Pro, ensuring their applications can pass review smoothly and attract their target users.
If you’ve created a visionOS app with a volume, you probably did it wrong
This article highlights a common mistake developers make when designing visionOS applications, especially when implementing the volume mode. Drew Olbrich points out that the sample code provided by Apple for creating volume windows does not take into account the "Window Zoom" setting in visionOS. If developers fail to properly handle this setting, the application content may be incorrectly cropped. Olbrich emphasizes the importance of mastering how to correctly adapt to the Window Zoom settings to ensure that applications display as expected under different user settings, avoiding poor user experiences due to oversight of this issue.
Mastering the Model Layer: Iron-Clad State Management in Model-Driven Apps
This article discusses the strategy of adopting state as the core in application development, elucidating through practical examples and code demonstrations how to implement effective state management in complex applications and expand the functionality and scale of applications through robust state management policies. Lucas van Dongen emphasizes that in the iOS development realm, architectures such as Model-View-ViewModel (MVVM), Model-View-Controller (MVC), and the practice of directly connecting the model to the view in SwiftUI have become mainstream. While these patterns provide an easy entry path for beginners, enabling rapid prototyping, developers often struggle to maintain the accuracy and clarity of application state, especially when facing numerous external events (such as push notifications, WebSocket, state restoration, or background tasks) as the application grows in complexity. The author also specifically notes that in certain cases, state should not directly drive the UI—such as with temporary states and navigation states, which should be managed as separate properties within the view model to avoid directly binding them to the shared state, thereby ensuring the clarity and maintainability of the application logic.
Mastering App Intents: Querying Made Easy
This article explores strategies for efficient data retrieval in iOS development, particularly emphasizing how App Intents simplify the sharing of data and logic between an application and its App Intent. Ashli Rankin demonstrates through a simple to-do list application example how to share data between an application's existing data model and an App Intent, with a focus on how to mark specific tasks in the task list as completed.
Support Swift macros with CocoaPods
This article, written by Soumya Mahunt, aims to guide developers on how to distribute macros introduced in Swift 5.9 via CocoaPods. Since macros are closely associated with the Swift Package Manager (SwiftPM), they might pose limitations for some use cases. To address this, Mahunt offers a solution by distributing macros through CocoaPods, thus overcoming the constraints related to SwiftPM. The author also believes that distributing macros via CocoaPods has subtle advantages over SwiftPM, including the ability to set lower deployment targets and avoid potential conflicts with swift-syntax versions, providing developers with an effective alternative.
肘子的话
Apple Vision Pro 于几天前开始交付用户,首批发货成绩令人瞩目,超出了预期。来自各方的反馈表明,除了重量和价格外,Apple Vision Pro 在多数体验方面都显著超越了竞争对手。已有不少用户通过社交媒体展示了在驾驶、健身、散步、工作等多种场景下使用该设备的视频,预示着一种新兴的赛博文化正在形成。期待这股热潮能够持续,并希望不久后能出现突破性应用,能够充分发挥 Apple Vision Pro 的全部潜力。
此外,上周苹果还宣布了名为 Pkl(发音为 Pickle)的编程语言的首次开源发布。Pkl 是一种专门为编写配置文件而设计的语言,旨在作为命令行工具、软件库或构建插件使用。Pkl 的开发者主张,配置文件最适合通过专用的配置语言来编写,这种语言结合了静态配置格式和通用编程语言的特点。值得注意的是,尽管 Pkl 是苹果官方发布的语言,但它目前还是基于 Java 实现的,并且只支持 IntelliJ、VSCode、Neovim 等编辑器。目前,Pkl 已提供了 Java、Kotlin、Swift 和 Go 的支持库,这意味着 iOS 开发者现在就可以在 Swift 项目中利用 Pkl 语言创建的配置文件。
至于苹果推出这门语言的动机以及它在苹果的开发生态中可能的应用场景,留给读者发挥想象。
随着春节——中国的传统佳节——的临近,我想提前向所有读者致以最诚挚的祝福:新春快乐,阖家幸福,身体健康,龙年大吉!
下周,我将与家人一同欢度春节,因此周报和博客都将停更一周。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
探讨 SwiftUI 中的属性包装器:@FetchRequest、@SectionedFetchRequest、@Query、@Namespace、@Bindable
在本文中,我们将对 @FetchRequest
、@SectionedFetchRequest
、@Query
、 @Namespace
和 @Bindable
等属性包装器进行探讨。这些属性包装器涵盖了在视图中对 Core Data 和 SwiftData 数据进行检索以及在视图中创建命名空间等功能。
这是“探索 SwiftUI 属性包装器”系列的第三篇文章( 共四篇 ),在前两篇中,我们分别探讨了:@State、@Binding、@StateObject、@ObservedObject、@EnvironmentObject、@Environment 和 @AppStorage、@SceneStorage、@FocusState、@GestureState、@ScaledMetric。
近期推荐
如果你是 Apple Vision Pro 的开发者,那么你一定要注意这些点
Apple Vision Pro 已正式上市,许多开发者不久( 或已经 )将收到他们所订购的设备。对于这些已经或即将成为 Apple Vision Pro 应用开发者的你来说,有哪些关键点需要留意呢?本文由 XReality Zone 的三位成员共同撰写,旨在为开发者提供一个关于设计和开发 Apple Vision Pro 应用的综合指南。文章涵盖了若干核心主题,包括如何进行设备调试、按照 Apple 的规范制作 App Store 视频和截图,以及如何利用不同的工具和技巧有效地创建出高品质的应用预览。这份指南旨在帮助开发者全面理解与 Apple Vision Pro 相关的开发细节,确保他们的应用能够顺利通过审核并吸引目标用户。
If you’ve created a visionOS app with a volume, you probably did it wrong
这篇文章揭示了开发者在设计 visionOS 应用过程中,尤其是在实现体积(volume)模式时,常犯的一个错误。Drew Olbrich 指出,Apple 提供的示例代码在创建体积窗口时未考虑到 visionOS 设置里的“窗口缩放”选项。若开发者未能妥善处理此设置,应用内容可能会遭到错误剪裁。Olbrich 强调,掌握如何正确适应窗口缩放设置至关重要,以确保应用在不同用户设置下能够呈现出预期的表现,避免因忽视此问题而导致的用户体验不佳。
Mastering the Model Layer: Iron-Clad State Management in Model-Driven Apps
本文探讨了在应用开发中心采用状态作为核心的策略,通过实践案例和代码演示,阐明了如何在复杂的应用中实施有效的状态管理,以及通过健全的状态管理策略来扩展应用的功能和规模。Lucas van Dongen 强调,在 iOS 开发界,模型-视图-视图模型(MVVM)、模型-视图-控制器(MVC)等架构,以及在 SwiftUI 中直接将模型与视图连接起来的做法已经成为了主流。虽然这些模式为初学者提供了易于入门的开发路径,使得快速原型开发成为可能,但在应用发展到较为复杂的阶段时,开发者往往难以维持应用状态的准确性和逻辑清晰性,尤其是面对众多外部事件(比如推送通知、WebSocket、状态恢复或后台任务)时尤为明显。作者还特别指出,在某些情况下,状态不应直接驱动 UI——如临时状态和导航状态,应通过视图模型中的独立属性进行管理,避免将它们直接绑定至共享状态中,以确保应用逻辑的清晰性和维护性。
Mastering App Intents: Querying Made Easy
本文探讨了在 iOS 开发中实现高效数据检索的策略,特别强调了 App Intents 如何简化应用程序及其 App Intent 之间数据和逻辑的共享。Ashli Rankin 通过构建一个简易的待办事项列表应用案例,演示了在应用的现有数据模型与 App Intent 间如何共享数据,尤其集中于如何将任务列表中的特定任务标记为已完成。
Support Swift macros with CocoaPods
本文由 Soumya Mahunt 撰写,旨在指导开发者如何通过 CocoaPods 分发 Swift 5.9 新引入的宏(macros)。由于宏与 Swift 包管理器(Swift Package Manager,简称 SwiftPM)紧密相关,因此可能对某些用例构成限制。为此 Mahunt 提供了一个解决方案,即通过 CocoaPods 分发宏,以此来克服与 SwiftPM 相关的限制。作者还认为使用 CocoaPods 分发宏相比 SwiftPM 具有一些微妙的优势,包括能够设置更低的部署目标和避免 swift-syntax 版本冲突的可能性,为开发者提供了一种有效的替代方案。