Weekly Comment
Apple recently notified developers submitting apps for review to include privacy manifest files in their apps if they use specific APIs. This requirement stems from the new policy introduced at WWDC 2023, aimed at compelling app developers and SDK producers to explicitly declare their app's privacy practices. By May 1, 2024, apps that fail to provide a complete privacy manifest will not pass the App Store's review process. Developers are required to provide clear privacy statements for the APIs or third-party libraries used, ensuring transparency and the protection of user privacy.
Besides the privacy manifest, developers were also required last week to verify and submit their app's merchant identity proofs on the App Store in compliance with EU regulations. This new requirement sparked fresh discussions in the developer community, with many seeking guidance on how to determine their own status. Apple's customer service advises consulting a legal advisor for clarity.
These updates reflect Apple's continuous adjustments to global legal and regulatory changes, suggesting that developers may need to comply with more such regulations in the future. This undoubtedly adds an additional burden on small development teams. While the intent to protect consumer interests is commendable, regulators should provide clearer and more understandable guidelines. Moreover, there is a hope that Apple will introduce more intelligent features in its development tools to help developers streamline the process of creating necessary privacy manifests. This would not only effectively safeguard user privacy but also allow developers to focus more on creating exceptional app experiences, rather than being bogged down by complex compliance demands.
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
Tips and Considerations for Using Lazy Containers in SwiftUI
In the SwiftUI framework, lazy layout containers such as List and LazyVStack provide an efficient way to display large datasets. These containers are ingeniously designed to dynamically build and load views only when necessary, thereby significantly optimizing the app's performance and memory usage efficiency. This article will introduce the following tips and considerations aimed at empowering developers to enhance app responsiveness and resource management when utilizing SwiftUI's lazy containers.
Custom Implementation Conforming to RandomAccessCollection
Implementing Infinite Data Loading
The Impact of the id Modifier on List’s Lazy Loading Mechanism
SwiftUI Only Retains the Top-Level State of ForEach Subviews in Lazy Containers
SwiftUI’s Passive Memory Resource Release for Specific State Types
Recent Selections
Swift Tooling: Windows Edition
Swift is actively expanding its support for various platforms. Beyond Linux, its toolchain for the Windows platform is also gradually being perfected. This article, presented by The Browser Company — the developers of the Arc browser — provides a detailed overview of the tools and development experience for using the Swift programming language on the Windows platform. The Arc browser, which is developed using Swift, is currently in the process of developing its Windows version, indicating more opportunities for Swift developers to leverage the potential of the Swift language across different platforms.
To build mature applications, merely having a comprehensive development language toolchain is not sufficient; an appropriate UI framework is also needed. OpenSwiftUI is a project initiated by Kyle Ye, aimed at creating an open-source version of SwiftUI that can be used for GUI app development on non-Apple platforms. Although the project is still in its early stages, it has already made significant progress. We look forward to more developers' attention and participation to collectively propel the development of this project.
Using environment variables in Swift
Environment variables are key-value pairs that influence app behavior, injected into the app's runtime as part of the process environment. They can be set at the system level or customized by the user. These variables are commonly used for configuration purposes, such as setting values to distinguish between development, testing, and production environments, used as feature flags, or for storing keys separately from the app's codebase. In this article, Tibor Bödecs explores the significance and application methods of using environment variables in Swift, providing a practical perspective to understand and implement environment variables, thereby enhancing the flexibility and security of app configuration.
Byte-sized Swift: Building Tiny Games for the Playdate
In an era dominated by AAA titles, Playdate stands out with its retro hardware, distinctive body design, and unique crank interaction, offering players a novel gaming experience. The manufacturer also provides an SDK to support developers in creating new games for Playdate. In this article, Rauhul Varma shares his experience using Swift's newly developed embedded language mode to create games for Playdate. He discusses not only the technical details of introducing Swift to a new platform, such as addressing calling conventions, CPU configuration, and memory layout discrepancies but also explains how to optimize the interaction between Swift and Playdate's C API, creating an API layer that is more in line with Swift's style, and explores its impact on game development.
Using @_silgen_name
to Forward Declare Functions in Swift and Improve Build Times
The @_silgen_name
attribute grants developers the ability to forward-declare functions in Swift, allowing them to directly reference functions in the compiled binary that might be invisible in the current module. This mechanism is extensively used in the Swift standard library to implement a feature akin to forward declarations in Obj-C, enabling the library to call deeper functions within the Swift runtime. In this article, Bruno Rocha elaborates on how to utilize @_silgen_name
for forward declaring functions and thereby optimize build times. He specifically notes that, as an underscored attribute, @_silgen_name
might conceal numerous potential risks, and its behavior could unpredictably change or become deprecated in the future. Therefore, he advises using this attribute in projects only when fully aware of the possible consequences.
Global actors in Swift
A global actor is essentially a special kind of actor that provides a unique global concurrency context for applications, with @MainActor
being the most typical example. This means that all code marked with a global actor tag runs in the same serial execution context, which is particularly crucial for managing global state or synchronizing resources that must be serialized. In this article, Majid Jabrayilov explores the use of global actors in Swift and guides on how to customize global actors, such as creating a consolidated type collection for accessing local storage to ensure a conflict-free state of disk files. Although global actors are not frequently needed in everyday app development, they prove to be exceptionally useful in certain specific scenarios, such as main-thread rendering.
肘子的话
苹果公司最近向提交应用审核的开发者发出通知,要求在应用中使用特定 API 的情况下添加隐私清单文件。这一要求源自 2023 年 WWDC 上的新政策,旨在让应用开发者及 SDK 制作者明确声明其应用的隐私操作。截至 2024 年 5 月 1 日,未能提供完整隐私清单的应用将无法通过 App Store 的审核流程。开发者需要为使用的 API 或第三方库提供明确的隐私声明,确保透明度和用户隐私的保护。
除隐私清单外,上周,开发者还需要针对欧盟法规,在 App Store 上确认并提交其应用的交易商身份证明。这一新要求在开发者社区引起了新的讨论,很多人寻求如何确定自身身份的指导。苹果客服给出的建议是请咨询身边的法律顾问。
这些更新反映了苹果不断适应全球法律法规变化的趋势,暗示开发者在未来可能需要遵守更多类似的规定。这对小型开发团队来说,无疑增加了额外的工作负担。虽然确保消费者权益的初衷是可贵的,但规则制定者应提供更加明确、易于理解的指南。同时,也期待苹果能在其开发工具中引入更加智能的功能,辅助开发者简化创建必需的隐私清单的流程。这样不仅可以有效保护用户隐私,还能使开发者更能专注于创造卓越的应用体验,而非被繁杂的合规需求所拖累。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
几个在 SwiftUI 中使用惰性容器的技巧和注意事项
在 SwiftUI 的框架中,惰性布局容器,如 List 和 LazyVStack,提供了一种高效展示大型数据集的方法。这些容器的设计精妙,它们仅在必要时才动态地构建和加载视图,从而显著优化了应用的性能和内存使用效率。本文将介绍如下技巧和注意事项,旨在赋予开发者利用 SwiftUI 惰性容器时增强应用响应性和资源管理的能力。
自定义遵循 RandomAccessCollection 的实现
实现无限数据加载
id 修饰器对 List 懒加载机制的影响
在惰性容器中,SwiftUI 仅保留 ForEach 子视图最顶层的状态
针对特定类型的状态, SwiftUI 释放内存资源不够积极
近期推荐
Swift Tooling: Windows Edition
Swift 正在积极扩展其支持的平台范围。除了 Linux 之外,其在 Windows 平台上的工具链也正在逐渐完善。本文由 The Browser Company(开发 Arc 浏览器的公司)呈现,详细介绍了在 Windows 平台上利用 Swift 编程语言的工具和开发体验。Arc 浏览器,一款基于 Swift 开发的浏览器,目前正在开发其 Windows 版本,这表明有更多的机会让 Swift 开发者在各种平台上发挥 Swift 语言的潜力。
要构建成熟的应用程序,仅有一套完善的开发语言工具链是不够的,还需要合适的 UI 框架。OpenSwiftUI 是一个由 Kyle Ye 创建的项目,旨在实现 SwiftUI 的开源版本,使其可用于非苹果平台上的 GUI 应用开发。该项目虽然还处于初期阶段,但已经取得显著进展。我们期待更多开发者的关注和参与,共同推动这个项目的发展。
Using environment variables in Swift
环境变量是影响应用程序行为的键值对,作为进程运行环境的一部分,在应用运行时被注入。它们不仅可以在系统级别被设定,也可由用户自定义。这些变量通常用于配置目的,如区分开发、测试和生产环境的设置值,作为功能标志使用,或用于独立于应用代码库存储密钥。Tibor Bödecs 在本文中探讨了在 Swift 中利用环境变量的重要性及其应用方法,提供了一个实用的视角来理解和实施环境变量,从而增强应用配置的灵活性和安全性。
Byte-sized Swift: Building Tiny Games for the Playdate
在这个 3A 大作充斥的时代,Playdate 以其复古硬件、鲜明的机身设计和独特的摇杆互动,为玩家带来了别致的游戏体验。制造商还提供了 SDK,以支持开发者为 Playdate 制作新游戏。Rauhul Varma 在这篇文章中分享了他使用 Swift 新开发的嵌入式语言模式为 Playdate 创建游戏的经历。他不仅讨论了引入 Swift 到新平台的技术细节,如解决调用约定、CPU 配置和内存布局差异等问题,还解释了如何优化 Swift 与 Playdate 的 C API 交互,创建了更符合 Swift 风格的 API 层,并探讨了其对游戏开发的影响。
Using @_silgen_name
to Forward Declare Functions in Swift and Improve Build Times
@_silgen_name
属性赋予开发者在 Swift 中前向声明函数的能力,允许他们直接引用编译后二进制中可能在当前模块中不可见的函数。这一机制广泛用于 Swift 标准库,以实现类似于 Obj-C 中前向声明的功能,从而让库能够调用 Swift 运行时更深层的函数。Bruno Rocha 在本文中详细阐述了如何利用 @_silgen_name
来前向声明函数,并借此优化构建时间。他特别指出,由于 @_silgen_name
是一个带下划线的属性,它可能隐藏着众多潜在的风险,并且其行为可能会在未来无预警地发生变化或被废弃。因此,他建议仅在完全理解可能的后果时才在项目中使用此属性。
Global actors in Swift
Global actor 实质上是一种特殊的 actor,为应用提供了独一无二的全局并发上下文,其中 @MainActor
是最典型的例子。这表示所有被指定全局 actor 标记的代码均在相同的串行执行上下文中运行,这在管理全局状态或同步必须串行处理的资源时显得尤为重要。在本文中,Majid Jabrayilov 探讨了 Swift 中全局 actor 的运用,并指导如何自定义全局 actor,比如为了确保磁盘文件的无冲突状态而创建一个集中访问本地存储的类型集合。尽管在日常应用开发中不经常需要用到全局 actor,但它们在某些特定场景下,如主线程渲染,显得格外有价值。
Let's VisionOS
Let's VisionOS 将于 2024.03.30 -2024.03.31 在北京举办。我将在 3.31 下午的会议上对 Observation 和 SwiftData 做介绍。感兴趣的朋友可以访问 活动官网 了解更多信息。
您好!為了協助開發者更便捷地創建privacy文件,提供了一個Python腳本,您可以在此處找到:GitHub - kimbely0320/update_privacy_info.py。此腳本具有以下功能:
檢查您的程式碼中是否使用了 Apple 官方文檔中的 Required Reason API:https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api 。
判斷您的專案中是否已包含Apple規定的SDK,具體要求可參考 Apple 支持的第三方SDK要求:
https://developer.apple.com/support/third-party-SDK-requirements/
自動從SDK套件中下載privacy文件,並根據API檢查結果在您的專案中新增相應的privacy文件。