Weekly Comment
Apple Uses M4 to Showcase Commitment to Embracing AI
On May 7, Apple finally updated the iPad series after a year and a half, with the highlight being the new iPad Pro equipped with the latest M4 chip. According to leaked benchmark data online, the M4 significantly outperforms the M2 and even M3 chips.
Apple claims that the M4 chip has significantly improved machine learning performance, especially enhancing the performance of the Neural Processing Unit (NPU). The full display of its AI capabilities may still need to be paired with the new system and APIs released at WWDC 2024. By debuting the latest M-series chip on the iPad Pro, Apple breaks tradition and fully demonstrates its determination to outpace other manufacturers in the AI era.
With the introduction of the M4 chip, I am full of anticipation for Apple's potential Mac product line this year. All signs point to Apple unveiling several AI-related updates, new features, and services at WWDC 2024. As a developer in the Apple ecosystem, I not only look forward to experiencing the convenience brought by AI during development but also hope Apple will introduce more secure and user-friendly APIs to help developers provide excellent AI services in their apps.
Given Apple's consistent emphasis on privacy, it is expected that most AI functionalities will run locally on devices. This not only poses higher demands on the device's AI capabilities but also presents a significant challenge in terms of energy consumption. After all, users do not want to see a significant reduction in battery life after updating to a new system. I am eager to see how Apple balances AI performance, energy consumption, privacy, development convenience, and user experience.
Although generative AI is currently experiencing a surge in popularity, and there are continuous reports of Apple's collaborations with top generative AI service providers, I firmly believe that everyday AI functions should primarily operate on local devices, using smaller models to serve users in an almost imperceptible manner. In the age of AI, energy-efficient hardware is crucial.
The iPad Pro equipped with the M4 chip will be more focused on scenarios that highlight its "Pro" level positioning. For most users, the new iPad Air, powered by the M2 chip and offering decent AI capabilities with a higher cost-effectiveness, may be a more suitable choice.
Whether or not you are focused on AI, it is undeniable that AI will spark a new wave of device upgrades and application experience innovations (at least at the marketing level). As developers, we must be prepared for this, even if we may not immediately offer or apply AI services, we should have a grasp of the basic operations and application scenarios of AI development.
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
Mastering the containerRelativeFrame Modifier in SwiftUI
The containerRelativeFrame
modifier starts from the view it is applied to and searches up the view hierarchy for the nearest container that fits within the list of containers. Based on the transformation rules set by the developer, it calculates the size provided by that container and uses this as the proposed size for the view. In a sense, it can be seen as a special version of the frame
modifier that allows for custom transformation rules. This modifier simplifies some layout operations that were previously difficult to achieve through conventional methods.
This article will delve into the containerRelativeFrame
modifier, covering its definition, layout rules, use cases, and relevant considerations. At the end of the article, we will also create a backward-compatible replica of containerRelativeFrame
for older versions of SwiftUI, further enhancing our understanding of its functionalities.
Recent Selections
Swift’s native Clocks are very inefficient
In Swift concurrency programming, ContinuousClock
and SuspendingClock
are used to manage time and delay tasks. ContinuousClock
is a continuously running clock that does not stop due to system sleep or other factors. In contrast, SuspendingClock
stops when the system is suspended, such as when entering sleep mode. The author, Wade Tregaskis, found through testing that although these two clocks have a very low absolute operational cost (mostly at the sub-microsecond level), their inefficiency can become a serious performance bottleneck when used frequently to handle time and timing issues.
This article has sparked widespread discussion within the developer community, with many developers sharing their views and suggestions on HackerNews.
How to train your first machine learning model and run it inside your iOS app via CoreML
In this article, Felix Krause meticulously explains how to implement your first machine learning model inside an iOS app using CoreML. The text thoroughly details the key stages of the entire process: data collection, data preparation and model training, model export, model integration, and the execution of the model on the device. Besides describing the specific technical steps for deploying a machine learning model within an app, the article also delves into relevant best practices and potential challenges encountered.
Turning AirPods into a Fitness Tracker to Fight Cancer
In this article, Richard Das explains how to utilize the motion sensor features of AirPods, combined with Core Motion, SwiftUI, and a bit of artificial intelligence technology, to develop an application that counts the number of push-ups performed. This project not only demonstrates the potential of technology to solve real-world problems but also reflects the personal satisfaction and fun involved in creating meaningful things.
This article is a response by the author to the 100 Push-Ups a Day Challenge launched by Cancer Research UK in April 2024, an initiative aimed at raising public awareness about cancer.
New Tutorial of TCA - Building SyncUps
The Composable Architecture (TCA) is a powerful framework, and its latest version 1.10 has introduced efficient state sharing tools. These tools enable seamless state sharing across various functional modules of an application, while also supporting the persistence of state data, such as user defaults and the file system, ensuring 100% testability of features. This tutorial provides a detailed guide on how to build a complex SwiftUI application named "SyncUps" from scratch, covering core principles such as using value types to model domains, state-driven navigation, simplifying domain models, controlling dependencies, and thoroughly testing application logic.
Migrating from CocoaPods to Tuist at Playtomic
Mohammadreza Koohkan
As the Playtomic project scaled up, the existing CocoaPods dependency management tool started to fall short. The team faced major issues including compatibility problems with SwiftUI and modern Swift packages, interruptions in the Xcode SwiftUI preview feature, slow storyboard loading, and increased complexity and maintenance difficulties with the Podfile. To address these issues, Playtomic decided to migrate to Tuist, a tool that optimizes project structure and enhances build efficiency.
In this article, Mohammadreza Koohkan thoroughly explains the challenges encountered during the migration process and the solutions implemented. The results of the migration show that Tuist not only resolved issues related to CocoaPods but also significantly improved the app's startup time and reduced the size of the binary files. Moreover, compared to CocoaPods, Tuist offers shorter compilation times.
Tuist is an open-source tool designed to help developers manage the configuration and dependencies of Xcode projects and workspaces. It simplifies project configuration and automates repetitive tasks, enhancing the development experience for large projects and teams.
Converting Local LLMs to Core ML Models - How to Use 🤗 Exporters
As generative artificial intelligence technology continues to evolve and become more widespread, an increasing number of developers are seeking to implement AI services based on local devices, extending these services to mobile devices as well. In this article, Shuichi Tsutsumi provides a detailed explanation on how to use the "Exporters" tool released by Hugging Face to convert local large language models (LLMs) into Core ML models. The article explores the efficiency and effectiveness of this tool through several model conversion examples, including attempts to customize conversions for smaller models. Despite some challenges encountered during the process, the author notes that the validation errors that appeared do not necessarily indicate problems with the models, as these comparisons are based on absolute differences, which are sometimes within acceptable ranges.
Exporters is a tool that wraps around coremltools, designed to simplify the process of converting Transformer models into Core ML models and to address various issues encountered during the conversion.
肘子的话
苹果用 M4 来展现拥抱 AI 的决心
在 5 月 7 日,苹果终于在时隔一年半后更新了 iPad 系列,其中最引人注目的是,新款 iPad Pro 直接搭载了最新的 M4 芯片。据网络上流出的跑分数据显示,M4 在性能上大幅超越了 M2 甚至 M3 芯片。
苹果宣称,M4 芯片在机器学习性能上有显著提升,特别大幅增强了神经处理单元(NPU)的性能。具体的 AI 性能表现如何,可能还需与 WWDC 2024 中发布的新系统和新 API 配合才能完全展现。在 iPad Pro 上首发 M 系列最新芯片,苹果此举打破传统,充分显示了其在 AI 时代赶超其他厂商的决心。
随着 M4 芯片的引入,我对苹果今年可能发布的 Mac 产品线充满期待。所有迹象都指向,苹果将在 WWDC 2024 上推出若干与 AI 有关的更新和新功能、新服务。作为一名苹果生态系统的开发者,我不仅期望在开发过程中体验到 AI 带来的便捷,也希望苹果能推出更多安全、易用的 API,帮助开发者在应用中为用户提供出色的 AI 服务。
鉴于苹果对隐私的一贯重视,预计大多数 AI 功能都将基于设备本地运行。这不仅对设备的 AI 性行能提出了更高要求,同时也对能耗是一大挑战。毕竟,用户不希望在更新新系统后,设备的电池续航时间大幅缩短。我迫切希望了解苹果如何在 AI 的性能、能耗、隐私、开发便利性和使用体验等方面找到平衡。
尽管生成式 AI 目前正处于热潮之中,且苹果与一些顶尖的生成式 AI 服务商之间的合作消息不断,但我始终认为,日常的 AI 功能主要应该基于本地设备,使用较小的模型,以对用户几乎无感的方式默默服务。在 AI 时代,高效节能的硬件设备显得尤为关键。
搭载 M4 芯片的 iPad Pro 将更加专注于能够突显其 “Pro” 级别定位的场景。对大多数用户来说,具备了一定 AI 能力且性价比更高的基于 M2 芯片的新 iPad Air 或许是更合适的选择。
不论你是否关注 AI,无可否认的是,AI 将引发新一轮的设备更新潮及应用体验革新(至少在营销层面如此)。作为开发者,我们必须为此做好准备,即便目前可能不立即提供或应用 AI 服务,也应对 AI 开发的基本操作和应用场景有所掌握。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
精通 SwiftUI 的 containerRelativeFrame 修饰器
containerRelativeFrame
修饰器从其所作用的视图开始,沿视图层次结构向上寻找最近的符合容器列表中的容器。根据开发者设置的变换规则,对该容器提供的尺寸进行计算后,以此作为视图的建议尺寸。从某种意义上讲,它可以视为一个允许自定义变换规则的特殊版本 frame
修饰器。这个修饰器使得一些以往难以通过常规方法实现的布局操作变得十分简单。
本文将深入探讨 containerRelativeFrame
修饰器,内容涵盖定义、布局规则、使用场景以及相关注意事项。在文章的最后,我们还将创建一个兼容旧版本 SwiftUI 的 containerRelativeFrame
复刻版,通过这一实践加深对其功能的理解。
近期推荐
Swift’s native Clocks are very inefficient( Swift 的原生时钟效率极低 )
在 Swift 并发编程中,ContinuousClock
和 SuspendingClock
被用于管理时间和延迟任务。ContinuousClock
是一个持续运行的时钟,不会因为系统睡眠或其他因素而停止。而 SuspendingClock
在系统挂起(如进入休眠状态)时会停止。本文作者 Wade Tregaskis 通过测试发现,尽管这两种时钟的绝对运行开销很小(大多数情况下为亚微秒级),频繁使用它们处理时间和计时问题时,它们的效率不足可能成为严重的性能瓶颈。
本文的观点在开发者社区中引发了广泛讨论,许多开发者在 HackerNews 上分享了自己的看法和建议。
How to train your first machine learning model and run it inside your iOS app via CoreML( 如何通过 CoreML 在你的 iOS 应用中训练并运行你的第一个机器学习模型 )
在这篇文章中,Felix Krause 细致地解释了如何利用 CoreML 在 iOS 应用内部实现您的第一个机器学习模型。全文详细介绍了整个过程的关键阶段:数据收集、数据准备与模型训练、模型导出、模型集成、以及模型的设备内执行。除了阐述如何在应用中部署机器学习模型的具体技术步骤外,本文还深入探讨了相关的最佳实践和可能遇到的挑战。
Turning AirPods into a Fitness Tracker to Fight Cancer( 将 AirPods 变为健身追踪器以助力抗癌 )
在这篇文章中,Richard Das 介绍了如何利用 AirPods 的运动传感器功能,通过结合 Core Motion、SwiftUI 和一点人工智能技术,开发出一个能够统计俯卧撑数量的应用。这个项目不仅展现了技术解决实际问题的潜力,也体现了创造有意义事物时的个人成就感和乐趣。
本文是作者响应 Cancer Research UK 在 2024 年 4 月发起的 100 Push-Ups a Day Challenge 活动,该活动旨在提高公众对癌症的意识。
New Tutorial of TCA - Building SyncUps( TCA 的新教程 )
Composable Architecture (TCA) 是一个功能强大的框架,其最新的 1.10 版本引入了高效的状态共享工具。这些工具使得在应用的多个功能模块之间无缝共享状态成为可能,同时支持状态的持久化存储,如用户默认设置和文件系统,保证了功能的 100%可测试性。本教程详细介绍了如何从零开始构建一个名为 “SyncUps” 的复杂 SwiftUI 应用,涵盖了如使用值类型模型化领域、从状态驱动导航、简化领域模型、控制依赖关系以及深入测试应用逻辑等多个核心原则。
Migrating from CocoaPods to Tuist at Playtomic( 从 CocoaPods 到 Tuist 的迁移:Playtomic 的案例研究 )
Mohammadreza Koohkan
随着 Playtomic 项目规模的扩大,原有的 CocoaPods 依赖管理工具开始显得力不从心。团队面临的主要问题包括:与 SwiftUI 和现代 Swift 包的兼容性问题、Xcode SwiftUI 预览功能中断、storyboards 加载缓慢、以及 Podfile 复杂性增加和依赖维护困难等。为解决这些问题,Playtomic 决定迁移到 Tuist,这是一款能够优化项目结构和提升构建效率的工具。
在本文中,Mohammadreza Koohkan 详细介绍了迁移过程中遇到的挑战和实施的解决策略。迁移结果表明,Tuist 不仅解决了与 CocoaPods 相关的问题,还显著改善了 app 的启动时间和减小了二进制文件的大小。此外,与 CocoaPods 相比,Tuist 的编译时间更短。
Tuist 是一个开源工具,旨在帮助开发者管理 Xcode 项目和工作空间的配置和依赖关系。它通过简化项目配置和自动化重复任务来改善大型项目和团队的开发体验。
ローカルLLMをCore MLモデルに変換する - 🤗 Exporters の使い方( 将本地大型语言模型转换为 Core ML 模型 )
随着生成式人工智能技术的不断发展和普及,越来越多的开发者希望在各种应用中实现基于本地设备的 AI 服务,并进一步将这些服务扩展到移动设备上。本文中,Shuichi Tsutsumi 详细介绍了如何使用 Hugging Face 发布的 “Exporters” 工具,将本地的大型语言模型(LLM)转换为 Core ML 模型。文章通过多个模型的转换实例,探索了该工具的效率和效果,包括对较小模型的自定义转换尝试。尽管过程中遇到了一些挑战,作者指出,出现的验证错误并不一定意味着模型有问题,因为这些比较是基于绝对差值进行的,而这些差值有时处于可接受的范围之内。
Exporters 是一个围绕 coremltools 的封装工具,旨在简化将 Transformers 模型转换为 Core ML 模型的过程,并解决转换中遇到的各种问题。