Weekly Comment
Time flies, and before we know it, it's already the end of March, with just over two months left until WWDC 2024. Recently, some developers have started listing the new features and functionalities they hope to see at WWDC 2024. Every developer within the Apple ecosystem has their own hopes and expectations, what are you looking forward to? Feel free to share your wishlist via X or comment, and I plan to feature these wishlists in one of the May editions of the newsletter.
Since launching the first edition of "Fatbobman's Swift Weekly" on October 9, 2023, the next issue marks a half-year milestone (taking into account a break for the Spring Festival). Currently, the newsletter reaches its audience through multiple platforms, including email, WeChat official account, Medium, Zhihu, and Juejin. Email subscribers have surpassed 1,300, with an opening rate steady at nearly 60%. These numbers, especially the email subscription count, have far exceeded my expectations and have greatly motivated me. I hope to reach 3,000 email subscribers by the end of 2024. If you haven't subscribed to the email version yet, please help me achieve this goal.
Next week, I will be attending the Let's VisionOS 2024 event in Beijing, where I'll share some insights on SwiftData and Observation. I'm also looking forward to engaging in face-to-face discussions with more friends at the event.
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
Practical SwiftData: Building SwiftUI Applications with Modern Approaches
In the previous article Concurrent Programming in SwiftData, we delved into the innovative concurrent programming model proposed by SwiftData, including its principles, core operations, and related considerations. This elegant programming solution has earned considerable praise. However, as more developers attempt to use SwiftData in actual SwiftUI applications, they have encountered some challenges, especially after enabling Swift’s strict concurrency checks. They found that SwiftData’s actor-based concurrency model is difficult to integrate with traditional application construction methods. This article will explain, in a tutorial-like manner, how to integrate SwiftData with modern programming concepts smoothly into SwiftUI applications and provide strategies to address the current challenges faced by developers.
Recent Selections
Building an ML App with SwiftUI (Part 1)
While Apple is still catching up in the generative AI field, it has already provided developers with mature native AI model solutions. DanielJia plans to showcase, through a series of articles, how to start from scratch to train a machine learning model and integrate it into iOS app development, with a strong emphasis on compatibility with SwiftUI. This article uses the YOLO model as an example, explaining the preparation of data, downloading and processing of datasets, and setting up the training environment for the model. It aims to provide iOS developers with a clear guide to developing machine learning applications.
Prompt to code in Xcode with Claude 3
Although there are rumors that Apple plans to introduce AI capabilities to Xcode this year, many developers are already eagerly integrating various AI services into their development workflow. In this article, James Rochabrun shows us how to develop an Xcode plugin that leverages Anthropic's latest language model, Claude 3, to provide assistance similar to Copilot. A highlight of the article is how to write effective prompts, which is crucial for generating precise code outputs. The image below displays the final implementation.
Oh Sh*t, My App is Successful and I Didn’t Think About Accessibility
Accessibility design can benefit a broader range of users, but due to cost and resource constraints, projects that fully consider accessibility throughout the development process are not common. In this article, Jacob Bartlett delves into the importance of implementing accessibility design in SwiftUI applications and demonstrates through practical examples how to apply accessibility development techniques at different stages of a SwiftUI project. He emphasizes that once developers have mastered these accessibility strategies, they should integrate these practices into their standard development workflow to prevent potential future issues. The article not only provides detailed technical guidance but also highlights developers' social responsibility, reminding them that in their pursuit of application success, they should not overlook those users who rely on accessibility features.
Sending Trial Notifications with Provisional Authorization on iOS
Apple's notification framework includes a provisional notification feature, allowing applications to silently send notifications to the Notification Center without direct permission from the user. This strategy cleverly guides users to a preliminary understanding of the app's notification capabilities. In this article, Natalia Panferova elaborates on how to effectively utilize this feature. She believes that implementing provisional notifications is an excellent strategy that can demonstrate the value of staying connected through the app while respecting user preferences. However, developers must ensure the usefulness, timeliness, and respect for user choices when implementing various notifications.
Getting Started with Structured Concurrency in Swift
Through structured concurrency, developers can effectively manage concurrent tasks, reducing common concurrency programming challenges such as race conditions and deadlocks. With the development of Swift 6, developers are expected to fully transition to adopting structured concurrency as their development paradigm. In this article, Joannis Orlandos introduces how to apply task groups and other structured concepts in applications to write more maintainable and comprehensible concurrent code. He also plans to explore Swift's actor model in future articles, as well as how to use this model to write code free from race conditions.
肘子的话
时间过得飞快,转瞬间我们已经迎来了 3 月底,距离 WWDC 2024 的召开也只有两个多月的时间。最近,一些开发者开始列出他们期待在 WWDC 2024 上见到的新功能和新特性清单。每位苹果生态的开发者心中都有属于自己的期待和愿望,你心中又期待着什么呢?欢迎将你的愿望清单通过 Twitter 或评论分享给我,我计划在 5 月的某一期周报中作一个愿望单特辑。
自从 2023 年 10 月 9 日推出首期 “肘子的 Swift 周报” 以来,到下一期,正好是半年的里程碑( 中间因为春节休息了一期)。目前,周报通过邮件、微信公众号、Medium、知乎和掘金等多个平台与大家见面。邮件订阅者已突破 1300 人,且开启率稳定在近 60%。这样的数据,特别是邮件订阅量,超出了我的预期,也极大地激励了我。我希望到 2024 年底,邮件订阅者能达到 3000 人。如果你还未 订阅邮件,请帮我实现这个目标。
下周,我将参加在北京举办的 Let's VisionOS 2024 活动,并分享一些关于 SwiftData 和 Observation 相关的内容。我也非常期待在此次活动中能与更多朋友进行面对面的交流。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
SwiftData 实战:用现代方法构建 SwiftUI 应用
在之前的文章 SwiftData 中的并发编程 中,我们深入探讨了 SwiftData 提出的创新并发编程模式,包括它的原理、核心操作及相关的注意事项。这种优雅的编程解决方案赢得了不少赞誉。然而,随着更多开发者在实际的 SwiftUI 应用中尝试使用 SwiftData,他们遇到了一些挑战:尤其在启用 Swift 的严格并发检查后,发现 SwiftData 基于 Actor 的并发模型与传统的应用构建方法很难融合。本文将采用类似教程的方式阐述如何将 SwiftData 与现代编程理念相结合,顺畅地融入 SwiftUI 应用之中,同时提供策略来应对目前开发者面临的挑战。
近期推荐
利用 SwiftUI 构建 ML 的 App ( Part 1 )
虽然苹果在生成式人工智能领域尚在努力赶超,但其早已为开发者提供了成熟的本地 AI 模型解决方案。DanielJia 计划通过一系列文章,展现如何从零开始训练一个机器学习模型,并将其整合到 iOS 应用开发中,着重强调了与 SwiftUI 的高度兼容性。本篇文章选取 YOLO 模型作为实例,讲解了数据的准备、数据集的下载与处理,以及设置训练环境进行模型训练的全过程,旨在为 iOS 开发者提供一个清晰的机器学习应用开发指南。
Prompt to code in Xcode with Claude 3
虽然有传言称苹果计划今年为 Xcode 引入 AI 功能,但许多开发者已经迫不及待地将各种 AI 服务融入他们的开发流程中。在本文中,James Rochabrun 向我们展示了如何开发一个 Xcode 插件,这个插件利用 Anthropic 的最新语言模型 Claude 3 来提供类似于 Copilot 的辅助功能。文章的一个亮点是如何编写有效的提示,这一点对于生成精确的代码输出极为关键。下图展示了实现的最终效果。
Oh Sh*t, My App is Successful and I Didn’t Think About Accessibility
无障碍设计能让更多用户受益,但由于成本和资源的限制,真正在开发过程中全面考虑无障碍性的项目并不常见。在这篇文章中,Jacob Bartlett 深入讲解了在 SwiftUI 应用中实施无障碍设计的重要性,并通过实际示例展示了如何在 SwiftUI 项目的不同环节中应用无障碍开发技巧。他强调,一旦掌握了这些可访问性策略,开发者就应该把这些做法整合到标准开发流程中,以预防未来可能出现的相关问题。文章不仅提供了详细的技术指导,也强调了开发者的社会责任,提醒他们在追求应用成功的同时,不应忽略那些依赖无障碍功能的用户。
Sending Trial Notifications with Provisional Authorization on iOS
苹果的通知框架中包含了一项临时通知功能,这使得应用能够在未获得用户直接许可的情况下,静默地将通知发送至通知中心。这一策略巧妙地引导用户初步了解应用的通知功能。在这篇文章中,Natalia Panferova 详细阐述了如何有效利用这一功能。她认为,实施临时通知是一种极佳的策略,能够在尊重用户偏好的同时,展示应用保持通信的价值,不过开发者在实现各种通知时,必须确保信息的有用性、及时性,并且尊重用户的选择。
Getting Started with Structured Concurrency in Swift
通过结构化并发,开发者能够有效管理并发任务,减少如竞态条件和死锁等常见的并发编程难题。随着 Swift 6 的发展,开发者预计将全面转向采用结构化并发的开发范式。Joannis Orlandos 在本文中介绍了如何在应用程序中运用任务组和其他结构化概念,以编写更加可维护且易于理解的并发代码。他还计划在未来的文章中探讨 Swift 的 actor 模型,以及如何利用该模型编写无竞态条件的代码。
我希望 Apple 能够更新一下 XcodeKit 。这个框架已经 N 年没有更新了,像是被完全抛弃了一样,导致 Xcode 的插件被 VSCode 和 IDEA 甩出 N 条街。这个问题在我们公司引入 GitHub Copilot 之后变得更严重,因为其他端的 IDE 都有原生的插件支持,我们只能用一个三方插件,即便是用了各种奇淫巧技,还是有很多问题。