Weekly Comment
Archiving and Awakening Memories
Last weekend, I attended a high school reunion. While I've maintained close contact with many classmates, there were a few I hadn't seen in decades since graduation. During the gathering, many classmates were immersed in reminiscing about our school days, with a projector on the wall displaying a meticulously crafted slideshow of old school photos.
Gazing at my younger self in those old photographs and listening to classmates recount anecdotes involving me, I once again fell into a daze: the person in the photos was indeed me, and the events they discussed were surely ones I had led or participated in, yet I had no recollection of them whatsoever. This scenario has occurred repeatedly at many gatherings.
I tend to view this phenomenon optimistically, not seeing it as a sign of declining memory. Perhaps the brain has stored these memories in a "deep archive" in some corner, requiring time and external assistance to retrieve them.
Fortunately, the iOS Photos app has the ability to automatically organize memories from vast collections of images. It occasionally presents events from the past decade or so in thematic collections, helping me awaken those archived memories.
I believe this is also the primary purpose of "journal" type apps - to intelligently aggregate information and preserve it as external digital memories. When I truly enter my twilight years, this information will become the key to awakening the dormant memories within me.
Choosing trustworthy data service providers, constantly upgrading storage space, and continuously paying for storage fees may sound easy, but with the explosive growth in the scale of data memories, long-term maintenance can consume considerable energy.
Perhaps it's time to revive some old traditions, timely converting parts of our digital memories into physical forms (such as printed photos, handwritten texts, etc.). This not only adds a backup method but also, compared to purely digital experiences, the tactile quality of physical objects may more easily evoke deeply stored memories.
Previous Issue|Newsletter Archive
If you appreciate my work and want to promote your product to the Swift and iOS developer community, sponsoring my platform could be an excellent opportunity for you.
Your support through Patreon, or Buy Me a Coffee helps keep this newsletter and blog running. Thank you for finding this content helpful!
Originals
How to Tile Images in SwiftUI
“I’ve got this!” I imagine this is the first reaction of most people upon seeing the title of this article. Although image tiling is not a commonly used feature, most developers can easily master its implementation. A search engine query reveals that almost all results point to the same solution — using the resizable
modifier. However, for a powerful UI framework, it is clearly not comprehensive to have only one solution for a requirement. In this article, we will explore two different implementations of image tiling and from there, introduce a less commonly used Image
construction method in SwiftUI.
Recent Selections
Exploring Writing Tools: Rewriting a Post About Writing Tools using Writing Tools
"Writing Tools" is part of the AI features introduced by Apple at WWDC 2024, offering capabilities such as proofreading, rewriting, and text transformation. In this article, Rudrank Riyam not only provides a detailed introduction to the various functions of Writing Tools but also shares his practical experience using them. Additionally, he explains to developers how to integrate Writing Tools into custom text views, how to control Writing Tools' behavior, and how to handle specific text ranges (such as code blocks).
Going Indie: From Side Project to Going Independent
As a renowned blogger and expert in the field of Swift programming, Antoine van der Lee recently made a significant decision: resigning from his full-time job to fully dedicate himself to his personal projects SwiftLee, RocketSim, and course development. In this article, Antoine shares his exciting journey from full-time employment to becoming an independent developer. Moreover, to help more developers with similar aspirations, he has carefully crafted an online course "From Side Project to Going Indie", aimed at guiding developers on how to successfully transform their side projects into full-time careers.
We sincerely wish him smooth sailing and great success in his new venture!
iOS WKWebView Page and File Resource Preload / Cache Research
In this article, ZhgChgLi discusses page preloading and caching strategies when using WKWebView in iOS development. The article provides a detailed introduction to HTTP caching mechanisms and analyzes various possible preloading and caching approaches, including improving HTTP caching, WKWebView preloading, using URLProtocol and WKURLSchemeHandler, among others.
Running iOS Performance Testing on CI
To ensure valid results from XCTMetric, developers must run performance tests on the same machine and physical device. This limitation effectively prevents running performance tests in a Continuous Integration (CI) environment. In this article, Alexey Alter-Pesotskiy discusses how to overcome this challenge and implement iOS performance testing in a CI environment. He proposes an innovative solution and provides detailed code examples using fastlane to implement this approach. This method not only offers iOS developers a new way to conduct performance testing in CI environments but also successfully overcomes some inherent limitations of the standard XCTest Performance tool.
One of the main goals of Swift 6 is to eliminate data races as much as possible through strict compiler-level checks. This goal has led to some relatively radical language changes, significantly impacting the migration of existing projects.
Some Experiences and Minor Complaints about Swift 6 Adaptation
The author expresses concerns about the direction of Swift's development:
Swift's current development doesn't seem to be focusing primarily on 'helping developers complete apps better and faster.' I'm not sure of the specific reasons, but whether it's the team prioritizing KPIs (such as rushing to transform the language and hastily releasing SwiftUI, or delivering on concurrent programming promises early), or eagerly trying to 'show off' in other areas (like Server Side or other operating system platforms), personally, I don't feel any happier coding in Swift 6 compared to Swift 3 or 4.
In this article, Wang Wei (onevcat) shares his recent experiences migrating several projects to Swift 6 and provides some practical migration tips. At the end of the article, the author calls for Swift's future development to focus more on improving development efficiency, helping developers complete applications faster and better.
Non-Sendable types are cool too you know
Matt Massicotte discusses the importance and application of non-Sendable types in Swift's concurrent programming. The article clarifies the concept of thread safety, explains the differences between Sendable and non-Sendable types, and provides solutions for related issues. As the article title suggests, the author emphasizes that non-Sendable types might be a better choice in certain situations and encourages developers to value these types.
Solving “Reference to captured var in concurrently-executing code” in Swift
When migrating to Swift 6 language mode, developers may encounter a series of new compiler warnings. One common warning is "Reference to captured var in concurrently-executing code". In this article, Donny Wals analyzes the reasons for this warning and provides several practical solutions, including converting captured variables from var
to let
, using explicit capture lists in closures, and creating constant captures before Task execution.
肘子的话
记忆归档和唤醒
上个周末,我参加了高中同学的聚会。尽管与不少同学仍保持着较为密切的联系,但也有些许同学自毕业后已经数十载未曾谋面。席间,众多同学沉浸在对往昔校园生活的回忆中,墙上的投影播放着由同学精心制作的在校时光旧照片剪辑。
凝视着那些旧照片中的自己,聆听着同学们叙述与我有关的点滴往事,我不禁再次陷入恍惚:照片中的确是我,他们谈论的事情想必也是由我主导或参与的,然而我本人却对此毫无印象。这种情形在诸多聚会中已屡次出现。
我倾向于乐观看待这一现象,不将其视为记忆力衰退的表现。或许大脑将这些记忆以“深度归档存储”的方式安置在某个角落,要将其提取出来需要一定时间和外力的辅助。
庆幸的是,iOS 的照片应用具备从海量影像中自动整理回忆的功能。近十余年来发生的事情,它会不时以专题形式呈现,助我唤醒那些已被归档的记忆。
我想,这也正是“手记”类应用的主要用途——智能汇总信息,将其保存为体外的数字记忆。待我真正步入暮年,这些信息将成为钥匙,帮助我唤醒体内已然沉睡的记忆。
选择值得信赖的数据服务商、不断升级存储空间、持续支付存储费用,虽然听起来都不难,但随着数据记忆规模的爆炸性增长,长期维护下来也需耗费不小的心力。
也许是时候重拾一些旧传统了,适时将部分数字记忆转化为实体形式(如纸质照片、手写文字等)。这不仅增加了一种备份方式,相较于纯数字化的体验,实体所带来的质感也更易唤起深藏的记忆。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
如何在 SwiftUI 中平铺图片
“这题我会!”。我想,看到本文标题时,这恐怕是大多数人的第一反应。尽管图片平铺并非常用功能,但多数开发者仍能轻松掌握其实现方法。通过搜索引擎查询,几乎所有结果都指向同一解决方案 —— 使用 resizable
修饰符。然而,对于一个功能强大的 UI 框架而言,若某个需求仅有单一解决方案,显然是不够全面的。在本文中,我们将探讨两种不同的图片平铺实现方式,并由此引申出一种在 SwiftUI 中较少使用的 Image
构建方法。
近期推荐
探索 Writing Tools 功能 ( Exploring Writing Tools: Rewriting a Post About Writing Tools using Writing Tools )
“Writing Tools” 是苹果在 WWDC 2024 中推出的系列 AI 功能中的一部分,它提供了校对、重写和文本转换等能力。在本文中,Rudrank Riyam 不仅详细介绍了 Writing Tools 的各项功能,还分享了自己的实际使用体验。并针对开发者讲解了如何在自定义文本视图中集成 Writing Tools,如何控制 Writing Tools 的行为,以及如何处理特定文本范围(如代码块)等内容。
独立之路:从副业项目到全职独立开发 ( Going Indie: From Side Project to Going Independent )
作为 Swift 编程领域的知名博主和专家,Antoine van der Lee 最近做出了一个重大决定:辞去全职工作,全身心投入到他的个人项目 SwiftLee、RocketSim 以及课程开发中。在这篇文章中,Antoine 分享了他从全职工作过渡到独立开发者的精彩历程。不仅如此,为了帮助更多怀揣相同梦想的开发者,他精心打造了一门在线课程 "From Side Project to Going Indie",旨在指导开发者如何将业余项目成功转变为全职事业。
由衷祝愿他的新事业一帆风顺,蒸蒸日上!
iOS WKWebView 页面与档案资源 Preload 预载 / Cache 缓存研究
在本文中,ZhgChgLi 探讨了 iOS 开发中使用 WKWebView 时的页面预加载和缓存策略。文章详细介绍了 HTTP 缓存机制,并分析了多种可能的预加载和缓存方案,包括完善 HTTP 缓存、WKWebView 预加载、使用 URLProtocol 和 WKURLSchemeHandler 等。
在持续集成环境中运行 iOS 性能测试 ( Running iOS Performance Testing on CI )
为了确保 XCTMetric 的运行结果有效,开发者必须在同一台机器和同一物理设备上运行性能测试。这一限制实际上阻碍了在持续集成 (CI)环境中进行性能测试的可能性。在本文中,Alexey Alter-Pesotskiy 探讨了如何克服这一挑战,在 CI 环境中实现 iOS 性能测试。他提出了一种创新的解决方案,并提供了使用 fastlane 实现该方案的详细代码示例。这种方法不仅为 iOS 开发者提供了在 CI 环境中进行性能测试的新途径,还成功克服了标准 XCTest Performance 工具的一些固有限制。
Swift 6 的一个主要目标是通过编译器层面的严格检查来最大程度地消除数据竞争。这一目标导致了一些相对激进的语言变更,给现有项目的迁移带来了显著影响。
Swift 6 适配的一些体会以及对现状的小吐槽
作者在文章中表达了对 Swift 发展方向的担忧:
Swift 现今的发展似乎并没有把绝对重点放在“帮助开发者更好更快地完成 app”上。我不清楚具体原因,但不论是团队更看重 KPI (比如一定要改造语言并匆忙发布 SwiftUI,或者是要把并发编程的饼尽早做出来),还是急于在别的领域“大显身手” (比如 Server Side 或者其他操作系统平台),我个人在 Swift 6 下写代码时,似乎并没有感觉到比 Swift 3 或者 4 时更快乐。
王巍在本文中分享了自己近期将几个项目迁移到 Swift 6 的经历并提供了一些实用的迁移技巧。在文章的最后,作者呼吁 Swift 的未来发展应更多地聚焦于提高开发效率,帮助开发者更快、更好地完成应用开发。
非 Sendable 类型也很酷 ( Non-Sendable types are cool too you know )
Matt Massicotte 探讨了 Swift 中非 Sendable 类型在并发编程中的重要性和应用。文章澄清了线程安全的概念,解释了 Sendable 和非 Sendable 类型的区别,并提供了处理相关问题的解决方案。正如文章标题所表达的,作者强调非 Sendable 类型在某些情况下可能是更好的选择,并鼓励开发者重视这些类型。
解决 “在并发执行的代码中引用捕获的可变变量” 警告 ( Solving “Reference to captured var in concurrently-executing code” in Swift )
在迁移至 Swift 6 语言模式时,开发者可能会遇到一系列新的编译警告。其中一个常见警告是 "Reference to captured var in concurrently-executing code"(在并发执行的代码中引用捕获的可变变量)。Donny Wals 在本文中剖析了此警告的出现原因,并提供了多种实用的解决方案,包括将捕获的变量从 var
转换为 let
、在闭包中使用显式捕获列表,以及在 Task 执行前创建常量捕获。
招募公告
❤️ 诚邀您加入 SwiftGG 的 Swift 6 中文教程翻译项目
SwiftGG 翻译组计划近期启动《The Swift Programming Language 6.0》中文教程的更新工作。
鉴于本次翻译工作量较大,SwiftGG 热切期待更多中文开发者社区的支持与协助。如果您对此项目感兴趣或愿意参与其中,欢迎通过以下方式与翻译组负责人思琦联系:
微博/X:@SwiftSIQI
此外,SwiftGG 翻译组最近更新了域名。请注意访问新的官方网站:https://swiftgg.team
Swift 中文版电子书可在此查阅:https://gitbook.swiftgg.team/swift
让我们携手努力,为 Swift 中文社区贡献力量!