Weekly Comment
I recently began redeveloping my "Health Notes" application. With the new version only supporting devices running iOS 17 and above, I've found greater freedom in choosing the technical direction.
This week, I restructured the state management code in my project using the Observation framework, and the results were surprisingly good. Beyond performance improvements, this class-based approach to state management has brought me many new insights, making it more aligned with SwiftUI practices. It has freed state splitting and combination from being confined to purely state management code.
The main issue with SwiftData currently lies in performance bottlenecks in certain scenarios, rather than the functionality itself. Although the framework is not yet mature, I still plan to try using it in my new project. Only through in-depth practice in real projects can I find solutions to certain problems (and I anticipate that some of these issues may persist in future versions). Despite the challenges, the prospect of developing in a manner more in tune with the Swift style is still exciting and highly anticipated.
Unfortunately, due to version restrictions, many developers will not be able to experience the convenience and shift in development mindset brought by revolutionary frameworks like Observation and SwiftData for some time. I sincerely hope that Apple, while introducing new frameworks, also considers forward compatibility, allowing a broader range of developers and users to benefit.
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
Mastering Relationships in Core Data: Practical Application
In the previous article, “Mastering Relationships in Core Data: Fundamentals” we explored the basic concepts and principles of relationships in Core Data. Building on that foundation, this article aims to share practical experience and techniques for handling relationships in Core Data. The goal is to assist developers in more effectively utilizing the relational features of the Core Data framework, thereby enhancing development flexibility and efficiency.
Recent Selections
ShaderGraph in visionOS
In this article, Yasuhito Nagatomo delves into ShaderGraph, an innovative approach to representing Shaders, which play a critical role in the rendering process of 3D scenes, primarily executing shading computations on GPUs. The author thoroughly introduces the overall concept of ShaderGraph in visionOS, its information sources, and selected example codes. He mentions in the article that, although the ShaderGraph Material in visionOS currently offers only basic functional nodes, he anticipates it will demonstrate a broader range of functionalities and potential for future development.
@Observable Macro performance increase over ObservableObject
This article provides an in-depth exploration of the application of the @Observable macro in SwiftUI, and its detailed comparison with ObservableObject. The author, Antoine van der Lee, thoroughly explains how to smoothly transition from ObservableObject and @Published to @Observable, focusing particularly on the advantages brought by adopting @Observable. These benefits are especially noticeable in managing multiple view model properties and significantly reducing unnecessary SwiftUI redraws. Van der Lee emphasizes that embracing this new macro is crucial for enhancing overall application performance by effectively avoiding unnecessary SwiftUI view redraws.
Adapting your App Icon to visionOS
This article delves into optimizing the design of application icons for the visionOS system. In visionOS, app icons feature a circular design, composed of a background layer and up to two non-background layers. This layered structure creates a three-dimensional effect, allowing the icon to subtly expand through the alpha channel of the non-background layers when viewed by users, thereby presenting a pronounced visual effect. Flora Damiano provides guidance on the setup process in her article, recommending adjustments to existing app icons rather than entirely new designs or simple replication. She also specifically notes the importance of avoiding depth elements that appear fixed from a single viewpoint in the design process and suggests simplifying the details of app icons to better suit the visionOS system.
Workaround for tricky issues when setting up camera using AVFoundation
This article, written by JuniperPhoton, thoroughly explores a range of challenging issues that may arise while setting up a camera using AVFoundation, drawing from the author's personal experience in developing their independent camera app, PhotonCam. The article not only lists several common problems but also provides specific solutions. For instance, it highlights a frequent issue: after enabling the ProRAW format for photography, the preview image might slightly shift vertically. Through a series of experiments, the author discovered that adjusting the zoom factor could effectively resolve this issue, although it may alter the field of view and dimensions of the previewed and captured images.
Chinese Word Correction in Swift
This article focuses on exploring how to perform Chinese word correction using Swift. Faced with common typographical errors in writing, the author tried several popular text correction services, only to find them limited in functionality, lacking support for markdown format, and costly for infrequent users. Consequently, the author embarked on developing their own correction tool, which has been released as an open-source project. In the article, the author comprehensively introduces the technical implementation plan of this tool, covering all stages from text file detection and sentence parsing to word detection and overall tool integration. The author also shares some of the main challenges encountered during development, such as accurately identifying text files, calibrating text segmentation, Chinese error detection and correction, and establishing communication with Python scripts in non-terminal environments.
Understanding and resolving merge conflicts
In his previous article "Git basics for iOS developers," Donny Wals introduced iOS developers to the fundamental concepts of Git. Continuing with this theme, the current article aims to help readers understand and resolve Git merge conflicts. The article thoroughly summarizes the regular operations of merging and branching in Git and emphasizes the importance of mastering different merging techniques. Wals advises readers on the crucial need to remain calm and patient while dealing with merge conflicts and suggests seeking colleagues' assistance when necessary. Additionally, the article explores the potential issues that can arise from force-pushing after rebasing in branches worked on collaboratively, cautioning readers to be particularly careful in such scenarios.
肘子的话
我最近开始重新开发我的“健康笔记”应用程序。由于新版本将只支持 iOS 17 及以上版本的设备,这让我在选择技术路线上享有更大的自由。
本周,我基于 Observation 框架重构了项目中的状态管理代码,测试结果出乎意料地好。除了性能提升之外,这种基于类的状态管理方式还为我带来了许多新的灵感,使状态管理更加贴合 SwiftUI 的实践。它让状态的拆分和组合不再局限于纯粹的状态管理代码。
SwiftData 当前的主要问题在于某些特殊场景下的性能, 而非功能本身。虽然该框架目前还不够成熟, 但我仍计划在新项目中尝试使用它进行开发。只有在实际项目中深入实践,才能找到解决某些问题的方法 (且我预计某些问题在未来版本中也会持续存在)。相比面临的问题, 能以更符合 Swift 风格的方式进行开发, 仍令我感到期待和兴奋。
由于版本限制,未来一段时间许多开发者仍将无法体验像 Observation、SwiftData 这样的革命性框架所带来的便利和开发思维上的转变,这是非常遗憾的一点。我真诚地希望苹果在推出新框架的同时, 也考虑向前兼容, 以让更多开发者和用户从中受益。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
掌握 Core Data 中的关系:实战
在上周的文章 掌握 Core Data 中的关系:基础 中,我们已经对 Core Data 中的关系基本概念和使用原则进行了探讨。本文将在此基础上进一步,分享关于处理 Core Data 关系的一些实用经验和技巧。目的是为了帮助开发者更有效地利用 Core Data 框架的关系功能,提高开发的灵活性和效率。
近期推荐
ShaderGraph in visionOS
在本文中,Yasuhito Nagatomo 深入探讨了 ShaderGraph,这是一种创新方式,用于表现着色器(Shader),后者在 3D 场景渲染过程中担当关键角色,专门执行着色计算,并主要运行在 GPU 上。作者详尽地介绍了 visionOS 中 ShaderGraph 的总体概念、信息来源及精选示例代码。他在文章中提到,尽管目前 visionOS 的 ShaderGraph Material 只提供了基本的功能节点,但他预期未来它将展现出更广泛的功能和发展潜力。
@Observable Macro performance increase over ObservableObject
本文深入探讨了在 SwiftUI 中应用@Observable 宏以提升性能,并将其与 ObservableObject 进行了深入比较。文章详尽地阐述了如何从 ObservableObject 和@Published 平稳过渡到@Observable 的方法,并着重讨论了采用@Observable 带来的优势,尤其是在管理多个视图模型属性时,对于减少 SwiftUI 重绘的显著改进。作者 Antoine van der Lee 强调,采纳这种新宏能有效避免 SwiftUI 视图的不必要重绘,对于提升整体应用性能至关重要。
Adapting your App Icon to visionOS
本文深入探讨了如何为 visionOS 系统优化应用图标的设计。在 visionOS 中,应用图标采用圆形设计,由一个背景层和至多两个非背景层组成。这样的层次结构营造出了立体效果,使得用户在观看图标时,图标能够通过非背景层的 alpha 通道微妙地膨胀,进而呈现出凸显的视觉效果。Flora Damiano 在文章中提供了设置流程的指导,她建议对现有的应用图标进行调整,而非全新设计或简单复制。她还特别指出,在设计过程中应避免添加固定视角下的深度视觉元素,并建议为了更好地适应 visionOS 系统,简化应用图标的细节元素。
Workaround for tricky issues when setting up camera using AVFoundation
本文由 JuniperPhoton 撰写,详细探讨了在使用 AVFoundation 设置摄像头过程中可能遭遇的一系列棘手问题以及相应的解决策略。这些内容源自作者在开发其独立摄像头应用 PhotonCam 时的实际体验。文中不仅列举了多种常见问题,还提供了具体的处理方法。例如,文章特别指出了一个常见问题:在启用 ProRAW 格式进行拍照后,预览图像可能会在垂直方向上轻微偏移。作者通过一系列实验,发现通过调整缩放因子便能有效解决这一问题,尽管这样做可能会对预览和捕获的图像视野及尺寸产生一定影响。
Swift 中文词语纠错
本文专注于探讨如何利用 Swift 进行中文词语纠错。面对写作中常见的错别字问题,作者尝试了几种流行的文字纠错服务,却发现它们功能有限,不支持 markdown 格式,且对非频繁使用者的成本较高。因此,作者着手自主开发了一个纠错工具,并已将其作为开源项目发布。文章中,作者详尽地介绍了这一工具的技术实施方案,涵盖了从文本文件检测、分句处理到词语检测和整体工具集成的各个环节。他还分享了开发过程中遇到的一些主要挑战,如如何准确识别文本文件、进行文本分句校准、中文纠错检测与校准,以及在非终端环境中实现与 python 脚本的互通。
Understanding and resolving merge conflicts
在之前的文章《Git basics for iOS developers》中,Donny Wals 向 iOS 开发者介绍了 Git 的基础知识。本文继续这一主题,旨在帮助读者理解和解决 Git 合并冲突。文章详细总结了 Git 中合并和分支的日常操作,并强调了掌握不同合并技巧的重要性。Wals 提醒读者,在处理合并冲突时保持冷静和耐心至关重要,并建议在需要时寻求同事的帮助。此外,文章还探讨了在多人协作的分支上进行变基操作后进行强制推送可能导致的问题,提醒读者在这类情况下需特别小心。