中文位于文章的下半部分
Weekly Comment
Last week, Alexandre Colucci released his annual report analyzing the usage of Swift and SwiftUI in the latest version of iOS. The report's findings were consistent with expectations, showing an increase in usage of both Swift and SwiftUI in iOS 17. Particularly exciting is the significant growth in the adoption of SwiftUI in Apple's own applications.
As a loyal user of SwiftUI, I have been eagerly awaiting Apple's deeper integration of this framework in more official applications. On one hand, this would allow Apple to gain a deeper understanding of the issues and shortcomings that arise when using SwiftUI in real-world applications, enabling faster feedback and optimization from the SwiftUI development team. On the other hand, it would accelerate the maturity and promotion of SwiftUI, making it more comprehensive, efficient, and stable.
Last October, the Ask Apple 2022 event received unanimous praise from developers. I have also been looking forward to Apple providing a similar communication platform this year. Perhaps Apple could make some adjustments to the format of the event, transitioning from a one-way Q&A to a more interactive two-way exchange. This way, while developers can ask Apple questions, Apple can also seek input from developers on certain issues or ideas, collectively promoting ecosystem development.
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 TipKit: Basics
TipKit is a framework newly introduced by Apple at WWDC 2023. It allows you to easily display tips in your applications. It can be used to introduce new features to users, help them discover hidden options, or showcase faster ways to accomplish tasks, among other scenarios. TipKit can run on various hardware environments and operating systems within the Apple ecosystem, including iPhone, iPad, Mac, Apple Watch, and Apple TV.
Developers can not only control the timing and frequency of tip display through settings such as rules and display frequency policies, but also obtain information about the status of tips and events associated with them through the API. While TipKit is primarily created for displaying tips, its functionality is not limited to that.
In this article, we will first learn and master the usage of TipKit.
I will explore the TipKit framework in two articles. In the next article, we will discuss more usage tips, considerations, implementation principles, and other extended topics on using TipKit in different scenarios.
Recent Selections
Being a good citizen in the land of SwiftSyntax
SwiftSyntax is a Swift library that developers can use to parse, analyze, generate, and transform the syntax tree of Swift source code. As a large project, SwiftSyntax has a long compilation time, which significantly increases the build time of projects that use it.
Usually, this is not a big issue because not many client applications directly depend on the SwiftSyntax library. However, with the introduction of Swift 5.9 and macros, the situation has changed.
Since macros rely on SwiftSyntax, projects that use macros experience a time penalty during the build process. Additionally, there is an increased possibility of dependency issues due to the use of different major versions of SwiftSyntax in the project (SwiftSyntax versions are closely tied to Swift versions).
In this article, Brandon Williams and Stephen Celis discuss how a responsible developer should mitigate the impact of these issues in the era of increasing adoption of SwiftSyntax.
On the Swift Forums, there is a discussion about the widespread adoption of SwiftSyntax in macros.
Apple’s use of Swift and SwiftUI in iOS 17
Since 2016, Alexandre Colucci has been analyzing the usage of the Swift language in iOS 10. Starting from iOS 13, he has also added statistics on the usage of SwiftUI. In this article, he reveals the analysis results for this year. Overall, the proportion of Swift and SwiftUI applications continues to grow in iOS 17. Here are the highlights:
iOS 17 includes 6030 binary files, an increase of 627 compared to iOS 16.
The number of binary files using SwiftUI has reached 385, a growth of 70% compared to iOS 16.
The number of binary files using Swift has reached 1516, an increase of 50% compared to iOS 16.
There are now 14 apps based on the SwiftUI app lifecycle, compared to only 4 in iOS 16.
SwiftUI has seen a significant increase in usage within Apple's own applications. The number of binary files exclusively using UIKit has decreased for the first time compared to the previous year.
Objective-C remains at the core of iOS, but the adoption rates of Swift and SwiftUI are rapidly increasing, while the proportions of Objective-C, C, and C++ continue to decline.
The original article contains more detailed analysis and richer charts.
On Launching your Indie App: Part 2
In 2019, Jordan Morgan launched his app Spend Stack on the App Store. The product used a paid download model and included the option for pre-orders. Prior to the product release, he identified his target users, created promotional videos, websites, press releases, and actively contacted the media. He also promoted the app through online platforms. He shared the entire process in "On Launching your Indie App: Part 1".
Recently, Jordan Morgan released his new product Elite Hoops on the App Store. This time, he took a more low-key approach and focused less on media outreach, instead targeting his specific users. The business model for this product was changed to free with a subscription. Compared to the first launch, the work was more relaxed but yielded better results.
The author provides a detailed account of the app's journey from pricing, target identification, pre-launch, promotion, and release. The article includes practical details and important considerations from the perspective of an indie developer, making it a valuable reference for developers planning to release an app.
Spring Animation from Scratch
Spring animation achieves smooth transitions and elastic effects in views by simulating the stretching and compression actions of a spring. It is an excellent tool for achieving smooth, natural, and seamless animation effects.
At WWDC 2023, Apple introduced spring animation functionality for SwiftUI and made it the default animation. However, many people may not be proficient in setting parameters such as object mass, spring stiffness, and system damping.
Kit Langton will demonstrate the implementation details of spring animation through a video. The video is divided into two parts, starting with a brief introduction to physics, outlining the mathematical knowledge behind spring physics to prepare for the algorithms we are about to write. Then, Kit Langton will use Xcode to build our own spring animation framework. Through code, we will replicate the default spring animation in SwiftUI.
Running Stable Diffusion with Core ML on iOS smoothly
This is an article that explains how to optimize the performance of the Stable Diffusion Core ML model on mobile devices. When using Core ML Stable Diffusion for offline image generation on Apple devices, developers often face issues such as slow execution and high memory usage. In this article, the author introduces various optimization methods, including enabling the reduceMemory option, using smaller models, and mixed-bit quantization. The following achievements were ultimately realized:
Before optimization:
Model loading and initialization took 5 minutes
High memory usage
Generating one image took approximately 90 seconds
After optimization:
Model loading and initialization took 100 seconds
Memory usage reduced to approximately 850MB
Image generation time reduced to approximately 10 seconds
肘子的话
上周,Alexandre Colucci 发布了每年一度的报告,分析了 Swift 和 SwiftUI 在 iOS 最新版本中的使用情况。报告结果与大家的预期一致,这两者在 iOS 17 中的使用率均有一定提升。尤其令人欣喜的是,在苹果自身的应用程序中,SwiftUI 的采用比例获得了不小的增长。
作为 SwiftUI 的忠实用户,我一直期待苹果能在更多官方应用中深入采用该框架。一方面,这能让苹果更深入地体会 SwiftUI 在实际应用中出现的问题和不足,有助于 SwiftUI 开发团队更快地对问题和需求作出反馈和优化;另一方面,也能加速 SwiftUI 的成熟与推广,让 SwiftUI 变得更加全面、高效、稳定。
去年10月,Ask Apple 2022 活动获得了开发者的一致好评。我也一直期待今年苹果能再次提供类似的沟通平台。或许,苹果对活动的形式做一定的调整,从单向的问答转变为更富互动性的双向交流。在开发者询问苹果的同时,苹果也能就某些问题或想法征求开发者的意见,共同促进生态圈发展。
PS:在本期的最后,我设置了一个关于非中文文章的标题是否需要翻译的投票,欢迎您投票、评论。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 Patreon, Buy Me a Coffee, 微信 支持我的创作。
原创
掌握 TipKit:基础
TipKit 是苹果在 WWDC 2023 上新推出的一个框架,可轻松在你的应用程序中显示提示。它可用于向用户介绍新功能,帮助他们发现隐藏的选项或展示完成任务更快的途径等场景。TipKit 可以运行在苹果生态系统的不同硬件环境和操作系统上,包括 iPhone、iPad、Mac、Apple Watch 和 Apple TV。
开发者不仅可以通过设定规则、显示频次策略等方式控制 Tip 显示的时机和频率,还可以通过 API 获取 Tip 的状态以及与 Tip 绑定的事件等信息。尽管 TipKit 是以展示提示为主要目的而创建的框架,但其功能不限于此。
在本文中,我们首先学习并掌握 TipKit 的用法。
我将用两篇文章探讨 TipKit 框架。在下篇中,我们将讨论更多使用技巧、注意事项、实现原理,以及在其他场景中使用 TipKit 等扩展话题。
近期推荐
Being a good citizen in the land of SwiftSyntax
SwiftSyntax 是一个 Swift 库,开发者可以使用它来解析、分析、生成和转换 Swift 源代码的语法树。作为一个大型项目,SwiftSyntax 的编译耗时较长,这会显著增加使用它的项目的构建时间。
通常情况下,这不是一个大问题,因为没有多少客户端应用程序直接依赖于 SwiftSyntax 库。但是,随着 Swift 5.9 和宏的引入,情况发生了变化。
由于宏会依赖 SwiftSyntax,这导致使用宏的项目在构建时产生了时间损失,同时也增加了由于项目中使用不同主要版本的 SwiftSyntax 而产生无法正确处理的依赖关系的可能性(SwiftSyntax 的版本与 Swift 版本具备紧密的联系)。
在本文中,Brandon Williams 和 Stephen Celis 探讨了在使用 SwiftSyntax 日渐增多的新时代,一个负责任的开发者应该如何将这些问题的影响减轻到最低。
在 Swift Forums 上,关于 SwiftSyntax 在宏中被广泛采用的 讨论。
Apple’s use of Swift and SwiftUI in iOS 17
从 2016 年开始,Alexandre Colucci 就开始分析 Swift 语言在 iOS 10 中的使用情况。从 iOS 13 开始,他又添加了对 SwiftUI 的使用统计。在这篇文章中,他公布了今年的分析结果。总体而言,在 iOS 17 中,Swift 和 SwiftUI 的应用比例继续增长。其中:
iOS 17 包含 6030 个二进制文件,比 iOS 16 增加了 627 个。
使用 SwiftUI 的二进制文件数量达到了 385 个,比 iOS 16 增长了 70%。
使用 Swift 的二进制文件达到了 1516 个,比 iOS 16 增加了 50%。
有 14 个应用现在基于 SwiftUI 的应用生命周期,在 iOS 16 中只有 4 个。
SwiftUI 在苹果自己的应用程序中明显增加。与前一年相比,专门使用 UIKit 的二进制文件数量首次减少。
Objective-C 仍然是 iOS 的核心,但 Swift 和 SwiftUI 的采用率正在快速增长,而 Objective-C、C 和 C++ 的比例持续下降。
原文中,包含了更详尽的分析和更丰富的图表。
On Launching your Indie App:Part 2
在 2019 年,Jordan Morgan 在 App Store 上架了他的应用 Spend Stack。产品采用了付费下载的模式,并开启了预购功能。在产品发布前夕,他提前确定了目标用户,事先制作了宣传视频、网站、新闻稿等资料,积极联系媒体,并在网络平台发帖宣传。他在 On Launching your Indie App: Part 1 中分享了整个过程。
不久前,Jordan Morgan 在 App Store 上架了他的新产品 Elite Hoops。这次他采取了更低调的方式,没有大力联系媒体,而是更专注于目标用户。产品的商业模式也改为了免费加订阅。相比第一次,这次的工作更加轻松,但收获更多。
作者从独立开发者的角度详细地讲述了 App 从定价、目标确定、预热、宣传到上线发布的过程。文中包含了许多实际操作的细节和需要注意的问题,对于有意发布 App 的开发者来说具有相当的参考价值。
Spring Animation from Scratch
弹簧动画通过模拟弹簧的拉伸和压缩动作来实现视图的平滑过渡和弹性效果。它是实现流畅、自然、连贯动画效果的绝佳工具。
在 WWDC 2023 上,苹果为 SwiftUI 增加了弹簧动画功能,并将其设置为默认动画。然而,很多人可能不太擅长设置物体的质量、弹簧的刚度和系统的阻尼等参数。
Kit Langton 将通过视频向大家展示弹簧动画的实现细节。该视频分为两个部分,首先进行简短的物理学介绍,概述弹簧物理学背后的数学知识,为我们即将编写的一些算法做好准备。然后,Kit Langton 将使用 Xcode 构建我们自己的弹簧动画框架。通过代码实现对 SwiftUI 默认弹簧动画的仿制。
Running Stable Diffusion with Core ML on iOS smoothly
这是一篇介绍如何在移动设备上优化运行 Stable Diffusion Core ML 模型的文章。在 Apple 设备上使用 Core ML Stable Diffusion 进行离线图片生成时,开发者常常要面对运行缓慢和内存占用过高等问题。在本文中,作者介绍了多种优化方法,包括启用 reduceMemory 选项、使用更小的模型、混合位宽量化(Mixed-bit quantization)等。最终实现了以下成果:
优化前:
模型加载和初始化需时 5 分钟
内存占用非常高
生成一张图片需时约 90 秒
优化后:
模型加载和初始化需时 100 秒
内存占用降低至约 850MB
图片生成时间降低至约 10 秒