# 20 : Time to Prepare for Swift 6

Published on

Weekly Comment

Recently, the Swift community announced the release process for Swift 6. Starting March 15, 2024, the release/6.0 branch will be branched off from the main branch, marking a significant acceleration in the Swift 6 project. It is anticipated to be released alongside the new version of Xcode in the second half of this year.

Swift 6 will introduce a stricter concurrency code checking mechanism, which will result in many of the current codes being unable to compile under Swift 6’s language mode. To provide developers with ample time to adapt, the Swift 6 compiler will continue to support the Swift 5 language mode, meaning developers don’t have to worry about their existing code not running in Swift 6. To fully leverage the latest features of Swift concurrency, developers are encouraged to enable the strict concurrency check flag (SWIFT_STRICT_CONCURRENCY) in their projects as early as possible in preparation for Swift 6.

Reflecting on my experience starting to learn the Swift language four years ago, I feel very fortunate because Swift 5 had already been released at that time, achieving ABI stability and thus reducing the learning cost. During the 5.x versions, although the core functionalities of the Swift language had stabilized, the community still added many new features and characteristics, which not only enhanced the functionality and applicability of Swift but inevitably raised the learning threshold for beginners. The plethora of syntactic sugar and new features in Swift can make many beginners feel utterly bewildered when facing complex code.

Things always have two sides: on one hand, developers hope Swift can become more powerful and adapt to more development scenarios and platforms; on the other hand, everyone also wishes it could be easier to learn and use, allowing developers to enjoy the conveniences of new features without additional learning burdens.

The introduction of macros attempts to balance this contradiction to some extent by encapsulating complex functions and features into macros, making it easier for more developers to benefit. However, in the current development environment, the use of custom macros not only significantly increases the project’s compile time but also affects Xcode’s response when the macros are complex, often leading to frequent errors in code auto-completion and macro expansion. With the release of Swift 6, it is hoped that Xcode will also improve, offering higher efficiency, stability, and contemporary AI-assisted programming capabilities.

Originals

How to Handle Optional Values in SwiftData Predicates

Fatbobman

SwiftData has revamped the mechanism for creating data models, incorporating a type-safe mode for predicate creation based on model code. As a result, developers encounter numerous operations involving optional values when constructing predicates for SwiftData. This article will explore some techniques and considerations for handling optional values while building predicates.

Recent Selections

How will Apple’s changes in the EU affect you?

Gabrielle Earnshaw

This article provides an in-depth analysis of the adjustments Apple has made to the App Store in the European Union to comply with the Digital Markets Act (DMA), exploring how these changes affect the promotion and payment models of iOS apps. Gabrielle Earnshaw suggests that developers releasing apps in the EU App Store need to carefully evaluate whether to accept the new business terms. For the vast majority of apps, maintaining the current business model may be the ideal choice. The article also emphasizes that although most apps may not immediately benefit from market alternatives or payment processing changes, these changes undoubtedly bring exciting developments to the iOS ecosystem, with the potential to offer innovation and improvements for developers and consumers alike.

Get the biometric authentication prompt for protected keychain items in the iOS simulator

Marco Eidinger

This article explains how to enable biometric authentication prompts for protected keychain items in the iOS simulator. Due to the absence of the Secure Enclave, a crucial security component that exists only on physical devices and is used for authentication processes such as fingerprint matching, keychain items protected by the kSecAttrAccessControl attribute cannot trigger biometric authentication prompts in the simulator. To bridge this gap, Marco Eidinger offers a clever solution: explicitly invoking the LAContext.evaluatePolicy(_:localizedReason:) method before performing keychain item access operations. This ensures that the simulator can simulate biometric authentication prompts, thereby reproducing a user experience similar to that on physical devices in the simulator.

Modding Plugins back into Xcode

Bryce Pauken

In this article, Bryce Pauken delves into how to reintegrate traditional plugin functionalities into Xcode. Before the release of Xcode 8, developers could modify and enhance Xcode’s internal functions using third-party plugins by accessing undocumented APIs, granting extensive customization and extension capabilities. This flexibility allowed developers to highly customize their development environment, despite the plugin system not being officially supported or documented. With Apple’s increased security measures limiting the execution of third-party code and plugin loading, the traditional way of using plugins gradually came to an end (starting with Xcode 14, Apple completely removed support for old-style plugins). Pauken not only thoroughly explains the key steps to reincorporate old-style plugin functionalities into Xcode but also introduces a tool named XcodePluginLoader, aimed at swiftly restoring plugin support and offering developers a powerful customization tool.

Twitter vs. X

Emerge Tools

This article analyzes the transformation the iOS client app underwent following Elon Musk’s acquisition and renaming of Twitter to X in 2022. Twitter has always been regarded as a mature application, but this purchase and rebranding signified a leap from a state of stable development to a new phase of “acting quickly and embracing disruption.” In the approximately six months since Twitter transformed into X, the size of the iOS app increased by 13.3MB. The article provides a thorough discussion on the various changes between the final version of Twitter (v9.54) and X (v10.25) within the iOS app, focusing on changes in app assets, dynamic frameworks, the SPM migration process, issues of resource duplication, and the introduction of the Grok AI chatbot, among other aspects. Despite changes in name and ownership, the author notes that the app did not undergo substantial changes in its overall architecture. The article also points out that by further optimizing duplicated resources within the app, such as icons, it could be possible to reduce the app’s size by up to 8MB.

Custom Core Data migrations

Pol Piella

Core Data migration involves updating the data model from one version to another. While Core Data can automatically handle this migration in many cases, some complex scenarios require developer intervention, guiding the migration process from the source to the target model by providing an exact mapping model. For particularly complex migration needs, writing a custom migration policy inherited from NSEntityMigrationPolicy is also necessary. This article, written by Pol Piella, details the implementation methods of custom Core Data migration, including creating mapping model files and custom migration policy classes. The article uses an application that stores music track information as an example, showing how to address data model expansion issues by introducing new entities and relationships and implementing custom migration strategies.

It’s worth noting that starting with iOS 17, Apple introduced a new migration mode in Core Data—Stage Migration, similar to the migration method in SwiftData, offering developers more flexibility and control. For more information about this new feature, you can refer to this article.

Get weekly handpicked updates on Swift and SwiftUI!

Fatbobman(东坡肘子)

I'm passionate about life and sharing knowledge. My blog focuses on Swift, SwiftUI, Core Data, and Swift Data. Follow my social media for the latest updates.

You can support me in the following ways