# 29 : Blog Speed Enhancement and Apple's New AI Model

Published on

Explore weekly Swift highlights with developers worldwide

Weekly Comment

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.

Originals

In-Depth Exploration of Overlay and Background Modifiers in SwiftUI

Fatbobman

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

An Tran

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

Majid Jabrayilov

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

Aryaman Sharda

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

Donny Wals

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

Toomas Vahter

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:

Get weekly handpicked updates on Swift and SwiftUI!

Buy me a if you found this article helpful