Weekly Comment
Older or Outer? Reminiscing About the Pre-Smart Era
Last Saturday, a two-way switch in our living room suddenly stopped working. This would have been a mundane electrical fault, but for me, it carried a deeper significance. It was the last of the many smart switches I installed 18 years ago that still functioned, and its "retirement" marked the complete sunset of traditional smart devices in my life.
Eighteen years ago, "smart home appliances" were nothing more than a vague concept, and smart switches lacked any unified standard. As a tech enthusiast back then, I purchased dozens of Schneider ULTI series switches and controllers for my home. I fondly remember those first few months after installation, immersed in the novelty of adjusting lighting ambiances with a remote control and eagerly showcasing these "futuristic" smart living scenarios to visiting friends. However, this enthusiasm lasted only a brief period. It wasn't that smart devices were inadequate, but I gradually realized that life could remain vibrant even without them, and manual close-range operations wouldn't significantly inconvenience me.
Today, "smart" has become a standard descriptor for household appliances. Refrigerators, televisions, air conditioners, washing machines, water heaters—almost every device purchased in recent years boasts "smart" and "networked" capabilities. While I can understand and accept the smart features of certain devices, I can't help but question the necessity when even kitchen appliances like range hoods and gas stoves start claiming network connectivity. Apart from a few products, I haven't integrated all home smart devices into app control, consistently wondering: Is this truly necessary? Is "smart" really that important? Has it become an irreplaceable life requirement?
The overarching concern of excessive "smartification" has similarly extended to the process of replacing my wife's car. Smart driving, oversized screens, and dazzling interaction modes have become the focal points of research and development for current automotive manufacturers, rapidly eroding traditional design philosophies. Now, finding a vehicle that retains sufficient physical buttons, maintains a modest screen size, and offers a driving experience aligned with human physiological sensations is becoming increasingly challenging. I'm not without worry: in a few years, the market might no longer offer models that aren't overwhelmingly "smart."
I am by no means a technological conservative—I'm still someone who loves learning and embraces new things. However, I'm increasingly aware that current products are trending towards ever more apparent over-"smartification". Though this may seem like a commercial gimmick, prolonged focus on smart features could lead manufacturers to neglect core functionalities and become overly enamored with superficial, flashy features. Whenever I perceive this trend, I involuntarily reminisce about products from the pre-smart era: pure and stable, authentic and grounded.
Whether we like it or not, humanity is perhaps inevitably heading towards a comprehensively smart era. That being the case, we should provide consumers with more choices, offering products that retain traditional operation methods and cleverly conceal smart functionalities for those unwilling to be engulfed by over-smartification. Technology's development should respect users' diverse needs, rather than unilaterally forcing progression.
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
Intentional Design or Technical Flaw? The Anomaly of onChange in SwiftUI Multi-Layer Navigation
SwiftUI provides the onChange
modifier, allowing developers to listen for changes in specific values within a view and execute corresponding actions when those values change. Intuitively, as long as a view is part of the currently visible branch of the view tree (active), the corresponding closure should be triggered when the observed value changes. However, in certain navigation scenarios, the onChange
modifier seems to become “selectively deaf,” inexplicably remaining silent even when the observed value changes. Is this a carefully designed feature by Apple, or a long-hidden code defect? This article aims to unveil this phenomenon and provide necessary caution to developers.
After the article was published, I received feedback from developers, who pointed out that they had encountered instances of
onChange
not working in different scenarios. This further suggests that this could be a long-standing bug that has not been adequately addressed.
Recent Selections
Using AppKit in Your Mac Catalyst App
While Apple has significantly enhanced macOS native capabilities in recent versions of SwiftUI, many developers still choose to quickly migrate their apps to macOS via Catalyst. Catalyst indeed simplifies the adaptation process, but it also has a clear limitation: it cannot directly use some AppKit components that Catalyst cannot bridge. In this article, Seb Vidal demonstrates how to leverage private _UINSView
and the AppKit bridging mechanism to introduce native AppKit components into a UIKit app, effectively bridging the gap in Catalyst and extending app functionality.
Calling Hidden Swift Functions
@_spi
is a powerful yet lesser-known attribute in Swift. Simply put, it allows methods to be "selectively hidden," making them unavailable via public APIs but still callable through specific methods if their signatures are known. Apple extensively uses this feature in several official frameworks (such as SwiftUI) to restrict certain functionalities to internal or specific modules. In this article, Noah Martin dives deep into how to call hidden functions in Swift frameworks and provides a detailed explanation of how to bypass Apple’s framework restrictions and use the undocumented System Programming Interface (SPI). This not only reveals how SPI works but also offers developers new ways to extend framework functionality.
EmergeTools used this technique in building SnapshotPreviews to successfully call an undocumented SwiftUI function that renders previews as images.
Working with Natural Language Framework
Apple’s Natural Language framework provides powerful tools for processing natural language in real-time. In this article, Artem Novichkov demonstrates several practical applications of the NL framework, including:
Semantic Text Search: Using
NLEmbedding
to achieve semantic matching, enhancing the intelligence of search features.Sentiment Analysis: Leveraging
NLTagger
to evaluate the sentiment of text, distinguishing between positive, negative, or neutral emotions.Dynamic Background Gradients: Creating real-time visual effects with iOS's MeshGradient technology based on sentiment scores.
macOS Tips for Programmers: Threading
When developing on macOS, thread management and priority settings are not only crucial for performance optimization but also directly affect system energy consumption and user experience. In this article, Luna Razzaghipour provides an in-depth analysis of macOS's unique thread management mechanisms, highlighting the central role of Quality of Service (QoS) in task prioritization and resource scheduling. Luna explains how developers can take full advantage of macOS's hardware capabilities by properly understanding QoS categories and widely using the Dispatch framework, ensuring both app performance and energy efficiency.
Dev Conversations #4: Matt Massicotte
Natan Rolnik and Matt Massicotte
As an expert in Swift concurrency models, Matt Massicotte has written several articles on the subject and contributed to the Swift 6 Migration Guide. In this interview, hosted by Natan Rolnik, Matt shares his extensive development experience and deep insights into Swift concurrent programming.
Debugging SwiftUI Layouts: Tips, Tricks, and Techniques
While SwiftUI makes building UIs fun and easy, debugging layout issues often proves to be a challenge for developers. In this article, Wesley Matlock shares a series of practical debugging techniques to help developers quickly identify and fix common layout issues in SwiftUI. Matlock points out that debugging SwiftUI layouts is not only a problem-solving process but also a great opportunity to gain a deeper understanding of the SwiftUI layout system. By skillfully utilizing visual debugging tools, Xcode's debugging features, and layout analysis techniques, developers can optimize layouts more efficiently and create higher-quality user interfaces.
Event
Advent of Code 2024
The Advent of Code 2024 will take place from December 1st to December 25th, with a new challenge released every day, progressively increasing in difficulty. This is a fantastic opportunity to sharpen your algorithmic skills and refine your programming expertise while enjoying the satisfaction of solving engaging puzzles during the year-end season.
The Swift community warmly invites all developers to participate in this annual event. Whether you are an experienced Swift expert or a beginner just starting your coding journey, Advent of Code offers a wide range of fun and challenging problems to spark your creativity and deepen your understanding of Swift’s versatile applications. It’s also a great opportunity to connect with fellow developers in the community, share ideas, learn new techniques, and exchange solutions.
To join, visit the Swift community’s forum post for detailed participation instructions, discussions, and helpful tips. Don’t miss this chance to make your holiday season both productive and rewarding!
If you’ve never worked on a Swift project outside of Xcode, this is a great opportunity to try. With the help of the Advent of Code Starter Template, you can experience the joy of coding Swift in alternative editors and unlock new possibilities.
肘子的话
Older or Outer?我开始怀念非智能时代
上周六,家里客厅的一个双控开关突然失灵了。这本是司空见惯的小故障,但对我而言,却别有一番意味。这是我 18 年前安装的众多智能开关中最后一个尚能正常工作的,它的“退役”,标志着传统智能设备在我生活中的全面落幕。
18 年前,“智能家电”还只是一个模糊的概念,智能开关也没有统一标准可言。作为当时的科技发烧友,我购买了数十个施耐德 ULTI 系列的开关和控制器。记得刚安装完成的那几个月,我沉浸在用遥控器调节灯光氛围的新奇中,热衷于向来访的朋友展示这“未来感”十足的智能生活场景。然而,这份热情也仅維持了短暂的几个月。并非智能设备不够出色,而是我渐渐意识到,即便不依赖它们,生活依然可以丰富多彩,人工近距离操作也并不会造成实质性的不便。
如今,“智能”已然成为家用电器的标配词汇。冰箱、电视、空调、洗衣机、热水器,近几年购入的电器几乎无一例外地标榜着“智能”和“联网”功能。我能理解并接受某些设备的智能化需求,但当连抽油烟机、燃气灶这类厨房设备都开始声称具备联网功能时,我不得不怀疑这种智能的必要性。除了极个别产品,我并未将家中所有智能产品都纳入 App 控制,因为内心始终认为:真的有这个必要吗?“智能”当真如此重要?已然成为生活的刚性需求了吗?
过度“智能化”的困扰同样延伸到为我正在为太太更换座驾这件事上。智能驾驶、超大屏幕、炫目的交互方式,已然成为当下车企竞相追逐的研发方向,且这股风潮也迅速侵蚀着传统车企的设计理念。如今,要找到一款保留足够实体按键、屏幕尺寸克制、提供契合人体生理感受驾驶体验的车型,正变得越来越困难。我不无担忧:再过几年,市场上或许就再难觅到不那么“智能”的汽车了。
我绝非技术保守主义者,依然是一个乐于学习、善于接纳新事物的人。然而,我愈发清晰地感受到:当前产品正以一种愈发明显的趋势过度“智能化”。尽管这更像是商业营销的噱头,但长此以往,厂商很可能会逐渐忘记在产品核心功能上下功夫,转而过分热衷于华而不实的表面文章。每每察觉到这种趋势,我就不由自主地怀念起非智能时代的产品:单纯且稳定,本真且踏实。
无论个人意愿与否,人类或许已不可避免地走向一个全面智能的时代。既然如此,我们更应该为消费者保留更多的选择空间,为那些不愿被过度智能化包围的人,提供一些保留传统操作方式、将智能功能巧妙隐藏的产品。技术的发展应该尊重使用者的多元需求,而非单方面地强制推进。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
有意为之还是技术缺陷?SwiftUI 多层导航中的 onChange 异常
SwiftUI 提供的 onChange
修饰器,使开发者能够在视图中监听特定值的变化,并在值发生改变时执行相应的操作。直觉上,只要某个视图位于当前可见的视图树分支中( 活动中 ),在观察的值发生变化时,对应的闭包就应该被触发。但在某些特定的导航场景下,onChange
修饰器似乎会“选择性失聪”,明明观察的值发生了变化,却诡异地保持沉默。这究竟是苹果精心设计的特性,还是一个隐藏已久的代码缺陷?本文将揭示这一现象并对开发者给予必要的提醒。
本文发表后,我陆续收到开发者的反馈,指出在不同场景下也遇到了
onChange
失效的情况。这进一步表明,这可能是一个长期存在且未被充分关注的 Bug。
近期推荐
在 Mac Catalyst 应用中使用 AppKit (Using AppKit in Your Mac Catalyst App)
虽然苹果在最近的 SwiftUI 版本中显著提升了 macOS 的原生功能,但许多开发者仍选择通过 Catalyst 将他们的应用快速迁移到 macOS 平台。Catalyst 确实大大简化了适配工作,但它也存在一个显而易见的局限:无法直接使用一些 Catalyst 无法转换的 AppKit 组件。在本文中,Seb Vidal 展示了如何利用私有的 _UINSView
和 AppKit 桥接机制,在 UIKit 应用中灵活引入原生的 AppKit 组件,从而弥补 Catalyst 的不足,并进一步扩展应用功能。
调用隐藏的 Swift 函数 (Calling Hidden Swift Functions)
@_spi
是 Swift 中一个功能强大却鲜为人知的属性。简单来说,它赋予了方法“选择性隐藏”的能力,使得这些方法无法通过公开 API 使用,但在了解其方法签名的情况下,仍可通过特定方式引入并调用。苹果在其多个官方框架(如 SwiftUI)中广泛使用此功能,以限制某些功能仅供内部或特定模块使用。在这篇文章中,Noah Martin 深入探讨了如何调用 Swift 框架中隐藏的函数,并详细展示了突破苹果框架限制、使用未公开的系统编程接口(SPI)的多种方法。这不仅揭示了 SPI 的运作机制,也为开发者提供了扩展框架功能的新思路。
EmergeTools 在构建 SnapshotPreviews 时使用了该技巧,成功调用了 SwiftUI 框架中未公开的将预览渲染为图片的功能。
使用自然语言框架 (Working with Natural Language Framework)
苹果的 Natural Language 框架为实时处理自然语言提供了强大的工具。在本文中,Artem Novichkov 展示了 NL 框架的多种实际应用,包括:
基于语义的文本搜索:通过
NLEmbedding
实现语义匹配,提升搜索功能的智能化水平。情感倾向分析:利用
NLTagger
评估文本的情感得分,区分正面、负面或中立的情绪。动态背景渐变:结合情感分数,使用 iOS 的 MeshGradient 技术创建实时更新的视觉效果。
macOS 编程技巧:线程管理 (macOS Tips for Programmers: Threading)
在 macOS 平台上进行开发时,线程管理和优先级设置不仅关乎性能优化,更直接影响系统的能耗和用户体验。在本文中,Luna Razzaghipour 深入解析了 macOS 独特的线程管理机制,强调了 QoS 在任务优先级和资源调度中的核心作用。Luna 指出,通过正确理解 QoS 类别并广泛采用 Dispatch 框架,开发者可以充分利用 macOS 的硬件特性,在保证应用性能的同时实现更高的能效。
开发者对话 #4:Matt Massicotte (Dev Conversations #4: Matt Massicotte)
Natan Rolnik and Matt Massicotte
作为 Swift 并发模型领域的专家,Matt Massicotte 发表了多篇关于这一主题的文章,并亲自参与编写了 Swift 6 迁移指南。在本期由 Natan Rolnik 主持的访谈中,Matt 分享了他的丰富开发经历以及对 Swift 并发编程的深入见解。
🪜 调试 SwiftUI 布局:技巧与方法 (Debugging SwiftUI Layouts: Tips, Tricks, and Techniques)
SwiftUI 虽然让构建 UI 变得轻松有趣,但调试布局问题却常常成为开发者的难点。Wesley Matlock 在本文中分享了一系列实用的调试技巧,帮助开发者快速定位和解决 SwiftUI 布局中的常见问题。Matlock 指出,调试 SwiftUI 布局不仅是解决问题的过程,更是深入理解 SwiftUI 布局系统的绝佳机会。通过巧妙利用视觉调试工具、Xcode 的调试功能以及布局分析技术,开发者可以更高效地优化布局,打造质量更高的应用界面。
活动
Advent of Code 2024
Advent of Code 2024 将于 12 月 1 日至 12 月 25 日 举行,每天发布一个全新的挑战,难度逐步递增。这是一个不可多得的机会,让你在年末的这段时间里通过动手实践提升算法能力,打磨编程技巧,同时享受解题带来的成就感。
Swift 社区热情邀请所有开发者参与这一年度活动。无论你是经验丰富的 Swift 专家,还是刚入门的初学者,Advent of Code 都能以其丰富有趣、充满挑战的题目激发你的创意,并带你深入探索 Swift 的广泛应用场景。同时,这也是一个绝佳的机会,让你与社区中的开发者交流心得、学习技巧、分享灵感。
如果你想参与,请访问 Swift 社区的论坛帖子,了解详细的参与方式、相关讨论以及实用建议。不要错过这个在学习与挑战中度过节日的精彩机会!
如果你还没有尝试过在 Xcode 之外开发 Swift 项目,这次活动将是一个不错的契机。通过使用 Advent of Code Starter 模板,你可以体验在其他编辑器中开发 Swift 代码的乐趣,解锁更多可能性。