Weekly Comment
Blog Speed Enhancement and Apple's New AI Model
Recently, I have been receiving intermittent feedback from blog readers indicating that the access speed is slow, with some readers even needing more than 10 minutes to load content. Considering I enabled global CDN services for the blog two years ago, such issues were not common before.
After reviewing announcements from our cloud service provider, I learned that they have launched a new service featuring a new CDN and enhanced security protection, and they plan to transition existing customers to this service over the coming period. Although I'm not certain if the current access speed issues are related to this, I have proactively switched to the new CDN service to address the problem sooner. This new service boasts 3,200 nodes worldwide, and I hope it will improve access efficiency for some users.
Additionally, statistics show that about 30% of visitors access the blog via mobile devices. Personally, I don't think mobile phones are the ideal tool for reading blog articles, but reality shows a need for optimization. Therefore, I have enabled a dynamic image resizing feature, which will provide smaller image sizes for mobile users, improving loading speeds and saving data while still meeting reading needs. However, since this feature was just launched, the image loading speed for mobile users might be slower in the short term (as smaller-sized images are dynamically generated based on demand) until all CDN nodes are updated, after which performance issues should be resolved.
Last week, Apple released a new AI model, OpenELM, available in several sizes: 270 million, 450 million, 1.1 billion, and 3 billion parameters. Clearly, this ultra-small-scale model is designed for use on local devices and is a key part of Apple's AI strategy. As WWDC24 approaches, Apple's AI strategy is becoming increasingly clear. Through collaborations with established AI service providers and projects such as OpenELM and Ferret-UI, Apple continues to offer more unique AI functionalities locally while maintaining privacy, something many users and developers anticipate seeing.
Apology Statement: In last week's newsletter, due to my oversight, the section containing content recommendations was omitted from the email received by readers. For this, I sincerely apologize. If you missed the wonderful articles in last issue, I recommend taking the time to read them so as not to miss any curated content.
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
In-Depth Exploration of Overlay and Background Modifiers in SwiftUI
In the toolbox of SwiftUI, overlay
and background
are two extremely useful view modifiers that play an indispensable role in various development scenarios. This article will delve into the unique attributes of these two modifiers, clarify their fundamental differences from ZStack
, and identify the scenarios they are best suited for.
Recent Selections
MLX: On-device machine learning on Apple Silicon
MLX is a neural network framework specifically tailored for Apple's M series chips. It provides a comprehensive set of Swift APIs covering classic models such as Llama, LoRa, Stable Diffusion, and Whisper. An Tran plans to explore different features of MLX daily over the next 30 days. This series is primarily aimed at iOS developers, especially those less familiar with other programming languages like Python. The tutorials will be as detailed and as easy to understand as possible.
Content Margins in SwiftUI
At WWDC 2023, SwiftUI introduced the contentMargins
view modifier, allowing developers to adjust margins for specific types of content within views, such as scrollable content, while keeping other elements like scroll indicators in their original positions. In this article, Majid Jabrayilov provides a detailed introduction to this new modifier and its differences from the safe area. Using simple examples, the article demonstrates how to manage content margins in SwiftUI on different devices, such as iPads and iPhones.
In this tweet, Jane demonstrates how to adjust the top margin of a List using
contentMargins
. For more about new features in ScrollView, read Deep Dive into New Features of ScrollView in SwiftUI.
Converting Codable Models To CSV
Although many tools and third-party libraries are available online to convert Codable models to CSV files, Aryaman Sharda preferred not to introduce a new dependency to solve what seemed like a straightforward issue. Therefore, he decided to implement this functionality using Swift's reflection capabilities and shared two methods: a basic implementation and an advanced one. The advanced implementation offers more customization options to meet more specific needs.
Dispatching to the Main thread with MainActor in Swift
In this article, Donny Wals discusses how to ensure that code executes on the main thread in Swift's concurrent programming using @MainActor
. The article details three methods to resolve compiler errors that typically occur when trying to modify a property annotated with @MainActor
from a non-isolated context. These solutions include applying @MainActor
to the entire class, to individual properties or methods, or using MainActor.run
within methods to manually specify that blocks of code run on the main thread.
Initializing @MainActor type from a non-isolated context in Swift
In this article, Toomas Vahter discusses a common issue in Swift's concurrent programming: how to initialize a type marked with @MainActor
from a non-isolated context, which is not allowed by default. The author shares the challenges encountered during implementation and adopted a strategy of delaying instance creation. By using lazy var
and closures, he ensures that instances are only created on @MainActor
when necessary. This method not only maintains the integrity of the type but also allows effective management from a non-isolated context.
With the impending arrival of Swift 6, more and more developers are starting to enable strict concurrency checking in their projects. As a very common issue, developers should strive to understand and master
@MainActor
. For more recent articles about@MainActor
, consider the following:
肘子的话
博客提速和苹果的新 AI 模型
最近,我不时收到一些博客读者的反馈,他们表示访问博客的速度较慢,有的读者甚至需要超过 10 分钟才能加载内容。考虑到我两年前已为博客启用了全球 CDN 服务,这种情况在以前似乎并不常见。
在查看云服务商的公告后,我了解到他们已推出了含全新 CDN 和增强安全防护的新服务,并计划在未来一段时间内将现有用户迁移至此。虽然我不确定当前的访问速度问题是否与此相关,为了尽早解决问题,我已将服务器切换到新的 CDN 服务。新服务在全球拥有 3200 个节点,我希望这能改善部分用户的访问效率。
此外,从统计数据来看,大约有 30%的访问者通过手机访问博客。虽然我个人不太认为手机是阅读博客文章的理想工具,但现实情况表明需要对此进行优化。因此,我启用了文章图片的动态尺寸调整功能,这将为手机用户提供更小的图片尺寸,在满足阅读需求的同时以提高加载速度并节省数据流量。然而,由于这项功能刚刚启动,短期内手机用户的图片加载速度可能会较慢( 图片将根据需求动态生成小尺寸版本 ),待所有 CDN 节点更新后,性能问题应能得到解决。
上周,苹果发布了新的 AI 模型 OpenELM,提供多种规模:2.7 亿、4.5 亿、11 亿及 30 亿参数版本。显然,这个超小规模的模型是被设计用于本地设备的,是苹果 AI 策略的关键部分。随着 WWDC24 的临近,苹果的 AI 策略日益明朗。通过与成熟 AI 服务商合作,以及通过项目如 OpenELM 和 Ferret-UI,苹果继续在保护隐私的前提下在本地提供更多独特的 AI 功能,我想这是许多用户和开发者所期望看到的。
如果您发现这份周报或我的博客对您有所帮助,可以考虑通过 爱发电,Buy Me a Coffee 支持我的创作。
原创
深入探索 SwiftUI 中的 Overlay 和 Background 修饰器
在 SwiftUI 的工具箱中,overlay
和 background
是两个极其有用的视图修饰器,它们在多种开发场景中扮演着不可或缺的角色。本文将深入探索这两种修饰器的独特属性,并明确它们与 ZStack
的基本差异,以及适合它们的应用场景。
近期推荐
MLX: On-device machine learning on Apple Silicon
MLX 是为 Apple M 系列芯片专门定制的神经网络框架。它提供了一整套易于掌握的 Swift API,并涵盖了 Llama、LoRa、Stable Diffusion 和 Whisper 等经典模型案例。An Tran 计划在未来 30 天内,每日深入探索 MLX 的不同功能。本系列文章主要面向 iOS 开发人员,特别是那些对 Python 等其他编程语言不太熟悉的读者。教程将尽可能地详尽且易于理解。
Content Margins in SwiftUI
WWDC 2023 中,SwiftUI 引入了 contentMargins
视图修饰符,允许开发者只对视图中特定类型的内容(如可滚动内容)进行边距调整,而保持其他元素(如滚动指示器)在其原始位置。在这篇文章中,Majid Jabrayilov 详细介绍了这一新修饰符及其与安全区域(safe area)的不同之处。通过一个简单的示例,文章展示了如何在不同设备上(如 iPad 和 iPhone)管理 SwiftUI 中的内容边距。
在这篇 推文 中,Jane 展示了如何利用
contentMargins
调整 List 的顶部边距。了解 ScrollView 的更多新功能,请阅读 深入了解 ScrollView 的新功能。
Converting Codable Models To CSV
尽管互联网上有许多工具和第三方库可以将 Codable 模型转换为 CSV 文件,但 Aryaman Sharda 并不希望为了解决一个看似简单的问题而在他的项目中引入新的依赖。因此,他决定采用 Swift 的反射机制自行实现这一功能,并分享了两种实现方法:基本实现和高级实现。相较于基本实现,高级实现提供了更多定制化选项,以满足更具体的需求。
Dispatching to the Main thread with MainActor in Swift
在本文中,Donny Wals 探讨了如何在 Swift 并发编程中使用 @MainActor
确保代码在主线程执行。文章详细讨论了解决编译器错误的三种方法,这些错误通常发生于尝试在非隔离上下文中修改被 @MainActor
注解的属性。这些解决方案包括:将 @MainActor
应用于整个类、单独对属性和方法应用 @MainActor
,或在方法内使用 MainActor.run
手动指定代码块在主线程执行。
Initializing @MainActor type from a non-isolated context in Swift
在这篇文章中,Toomas Vahter 探讨了一个常见的 Swift 并发编程问题:如何从非隔离上下文初始化标记为 @MainActor
的类型。由于默认情况下不允许这样做,作者分享了他在实现过程中遇到的挑战。为了解决这一问题,Toomas 采用了延迟创建实例的策略,通过使用 lazy var
和闭包确保实例只在必要时才在 @MainActor
上创建。这种方法不仅保持了类型的完整性,还允许从非隔离上下文进行有效管理。
随着 Swift 6 的即将到来,越来越多的开发者开始在他们的项目中启用并发严格检查功能。作为一个十分常见的议题,开发者应该尽量对
@MainActor
有所了解和掌握。更多近期关于@MainActor
的文章:
活动
💫 AdventureX 2024 年轻人第一场黑客松正式开启报名了!
🪄 你是否经常在各类黑客松见到这样的参与者:
一个项目反复参加,只想混奖金
技术实力不够,只想当 Free rider
眼睛没有光,创业只想圈钱套现
思维乏味,点子一点都不 SHOCKING
为了整治黑客松「乱象」,AdventureX 团队决定举办一场异类的黑客松,并邀请所有 26 岁以下具有开发、设计、营销三大能力之一的“当代嬉皮士”在 7 月 15 到 19 日来到杭州参与我们的线下活动。
🔥 在 5 天时间内与 200 名 26 岁以下来自全球四大洲的“当代嬉皮士”同频共振 🔨 极限创业,开发软件、网页、硬件产品,无产品方向限制 🆓 活动完全免费,此外将提供免费云服务器、大量 AI Credit、web3 资源、免费协同办公软件 🌟 真格合伙人刘元、独立开发者图拉鼎、设计师 Allen、海辛、阿文等会作为嘉宾来到现场 🤖 硬件实验室,提供 3D 打印机、VisionPro、树莓派、Monocle(AR 版树莓派)和工业级硬件设施 💰 总共高达 ??? w+人民币的奖金和各类礼品,此外还有大量来自国内一线基金的投资人参与 🎠 活动期间会有日出爬山、撸猫、BBQ、伍德斯托克音乐节等特色活动
如果你是 26 岁以上的资深“嬉皮士”,欢迎直接 DM 我们报名「指引者」,你将引导所有的“当代嬉皮士”完成最疯狂的产品,并体验 5 天的全程活动!
🚀 加入 2024 线下活动,也许我们的努力会让你找到一个真正属于你的地方。无论它存在了多少次,多年后也有人会和我曾经一样感叹:“在那里,真正点燃了我对 XX 的热情之火”,或“在那里,我认识了一生的挚友”…… 这才是我们举办 AdventureX 的终极目的。
🌍 访问 http://adventure-x.org 立即开启变革!