# 2 : Embracing a Bright Future, Yet Bound by Reality

Published on

Get weekly handpicked updates on Swift and SwiftUI!

Weekly Comment

From the launch of the first beta version at WWDC 2023, SwiftData has been around for four months in the blink of an eye. In the past month, I have devoted considerable effort to researching and learning it, and have written several articles about it.

SwiftData largely addresses several major criticisms of Core Data. This is mainly reflected in the following aspects: pure code modeling, diversity of property types (automatic mapping of types that conform to RawRepresentable and Encodable), a safer and more elegant experience in concurrent programming, type-safe predicates, and better integration with SwiftUI. Among them, the logic of creating data models and the new approach to concurrent programming have left a deep impression on me.

Unfortunately, ideals are lofty while reality is harsh. Just when I was eager to build a brand new application with SwiftData, the limited predicate expression capabilities became a hindrance. The new predicate API fails to seamlessly work with composite types (resulting in diminished advantages of new property types) and also falls short in representing object relationships. Moreover, predicates belong to the Foundation framework, which adds to the coordination difficulties between the two development teams.

Except for the predicates, poor stability, limited API, and numerous bugs are the problems that have to be dealt with.

As the most important persistence framework in the future Apple ecosystem, SwiftData is designed very elegantly, but its implementation is somewhat hasty, which is undoubtedly regrettable.

I will postpone starting the development of iOS 17+ applications using SwiftData and observe if the predicates and stability are improved in the upcoming updates. However, through my research on the implementation of SwiftData, I have gained a deeper understanding of how to use Core Data in a modern way and how to create Core Data applications that are suitable for migration to SwiftData. It has been a fruitful learning experience.

In the future, I will share several articles related to SwiftData and look forward to its early improvement!

Originals

Concurrent Programming in SwiftData

fatbobman (东坡肘子)

Concurrent programming in Core Data may not be difficult, but it is full of traps. Even with ample experience in Core Data, a slight negligence can introduce vulnerabilities into the code, making the application unsafe. As the successor to Core Data, SwiftData provides a more elegant and secure mechanism for concurrent programming. This article will introduce ways SwiftData addresses these issues and offers developers a better experience with concurrent programming.

During the writing process, it was found that there was a lot of content to be explained, and it was eventually divided into three parts. The first two parts are Exploring CoreData — From Data Model Creation to Managed Object Instances and Unveiling the Data Modeling Principles of SwiftData.

Recent Selections

Deep Understanding of Observation - Principles, Back Porting, and Performance

onevcat

At WWDC 23, Apple introduced a brand new Observation framework aimed at addressing the confusion and performance issues of state management in SwiftUI. The way this framework works seems quite magical, even without any special declaration, it allows for property-level subscriptions in Views, thus avoiding unnecessary refreshes. This article will delve into the underlying principles to help you:

  • Understand the essence and implementation mechanism of the Observation framework
  • Compare its advantages with previous solutions
  • Introduce a way to make Observation backward compatible to iOS 14
  • Explore some considerations and trade-offs in handling SwiftUI state management

This text explains the implementation principle of Observation, but more importantly, the author has created a third-party library called ObservationBP. By wrapping the source code of Observation, developers can use the functionality of Observation in lower system versions.

Great SwiftUI

Aviel Gross

This is an article on SwiftUI.wtf that the author recently updated. Aviel Gross describes this article as a collection of best practices, tips, and tricks for the SwiftUI codebase to fully leverage its advantages. The article is divided into three sections:

  • Behavior: Make your code do what you want it to do, or what you think it should be doing
  • Structure: How to layout your code (where to put logic, how to build the body etc)
  • Performance: Make your app run fast, and increase its stability

The experiences and tips listed in the article have a considerable universality, but they are not absolute rules. In individual scenarios or needs, adjustments should be made based on the actual situation. Therefore, understanding the principles behind them is more important than memorizing the techniques.

“Cracking” the Easter Eggs in visionOS Beta 1.4

V2XR

In this article, the author introduces some “Easter eggs” about the VisionOS system that he discovered from the simulator files of version 1.4. These include system applications, spatial photos and panorama photos in the album, from Optic ID to EyeSight to Digital Human, wearing prompts (RealityCoverSheet), and lens prescriptions (CorePrescription), among other content. Through the analysis of this information, we can get a glimpse of some design details and progress of visionOS.

Designing for spatial computing: from iOS and iPadOS to visionOS

Emanuele Agosta

Apple Vision Pro represents a significant revolution in the field of spatial computing, providing users with unprecedented interactivity and immersion. In this article, Emanuele Agosta will explore the design principles of spatial computing and the key considerations for seamlessly transitioning iOS/iPadOS applications to visionOS applications, while providing foundational guidance.

Working With XcodeKit for SwiftLeeds

Aryaman Sharda

As the author of EditKit Pro, Aryaman Sharda was invited to give a talk on Working with XcodeKit at SwiftLeeds. In his presentation, he shared some experiences and tips on developing Xcode Source Editor Extensions. This article provides the presentation slides used during the talk.

EditKit Pro is an Xcode Source Editor Extension that provides a set of tools to help developers write better, cleaner, and more efficient code. It integrates many features such as quick code formatting, creating Codable models, generating mock data, sorting lines by length, organizing SwiftUI views, and more. You can get the source code of EditKit Pro here or directly download and install it from the App Store.

Interoperability: Swift’s Super Power

Saleem Abdulrasool

In this article, Saleem Abdulrasool shares their experience of developing Windows applications using Swift. They demonstrate the potential of Swift as a cross-platform language by showcasing how to access Windows API and COM interfaces through the built-in interoperability features of the Swift language.

Swift 5.9 introduces bidirectional interoperability support between Swift and C++. By generating C++ header files, Swift APIs can be exposed to C++ in a similar C++ interface format, greatly simplifying the process of incorporating Swift into existing C++ code. This feature is enabled by default and does not require any additional code modifications. This new functionality allows Swift to seamlessly integrate into the existing C++ ecosystem while still maintaining its own distinctive features.

Weekly Swift & SwiftUI insights, delivered every Monday night. Join developers worldwide.
Easy unsubscribe, zero spam guaranteed