Learning Swift 6.2

I am building a SwiftUI Application (MVVM+Repository) named CMYKColor using Xcode 26.1.1.
This is my first time trying to use Swift Language Version: Swift 6 and Default Actor isolation: MainActor.
I encountered issues during the compilation phase, which were only resolved with the help of AI. This indicates that I am completely unfamiliar with the features that Swift 6.2 aims to bring, and I suddenly don't know how to start writing Swift 6.2 code.

The main problem is how to correctly apply the numerous keywords (actor, @MainActor, @globalActor, Sendable, @Sendable, @unchecked Sendable, sending, nonsending, nonisolated, nonisolated(nonsending), @concurrent, @concurrent nonisolated and Xcode 26 Default Actor Isolation: MainActor or nonisolated) to the right places, such as classes, structs, variables, global variables, or functions, and when to use the correct keywords.

Do you have any recommendations for articles or books? Thank you!

CMYK.swift
----------
import Foundation
import Observation

@Observable class CMYK: Identifiable {
    let id: UUID
    var c: Double
    var m: Double
    var y: Double
    var k: Double
    
    init(id: UUID = UUID(), c: Double, m: Double, y: Double, k: Double) {
        self.id = id
        self.c = c
        self.m = m
        self.y = y
        self.k = k
    }
    
    convenience init(from cmykModel: CMYKModel) {
        self.init(id: cmykModel.id,
                  c: cmykModel.c,
                  m: cmykModel.m,
                  y: cmykModel.y,
                  k: cmykModel.k)
    }
}
CMYKModel.swift
---------------
import Foundation
import SwiftData

@Model class CMYKModel {
    var id: UUID
    var c: Double
    var m: Double
    var y: Double
    var k: Double
    
    init(id: UUID = UUID(), c: Double, m: Double, y: Double, k: Double) {
        self.id = id
        self.c = c
        self.m = m
        self.y = y
        self.k = k
    }
    
    // Main actor-isolated property 'c' can not be referenced from a nonisolated context
    // Main actor-isolated property 'm' can not be referenced from a nonisolated context
    // Main actor-isolated property 'y' can not be referenced from a nonisolated context
    // Main actor-isolated property 'k' can not be referenced from a nonisolated context
    // AI suggests adding @MainActor (By default it’s already using MainActor, isn’t it? Why add @MainActor again).
    convenience init(from cmyk: CMYK) {
        self.init(id: cmyk.id,
                  c: cmyk.c,
                  m: cmyk.m,
                  y: cmyk.y,
                  k: cmyk.k)
    }
}

Relax. It is not that scary actually. :slight_smile:

I have found this article very useful: Exploring concurrency changes in Swift 6.2.

Donny Wal does an excellent job of explaining it, using clear language and examples.

  • @globalActor generally supports a singleton for actors
  • @MainActor runs code on the main thread/actor as shorthand
  • @unchecked means that you are claiming that a compiler check doesn’t prove that you meet criteria for the expectations but your code takes responsibility for the safe maintenance of the expectations
  • @concurrent brings execution out of any particular actor and is intended to support this behavior due to a flag which alters the prior behavior
  • Sendable says that a type can safely cross actor boundaries
  • Isolation refers to actor Isolation and the crossing of control flow and data over actor boundaries
  • Default Actor/Isolation set boundaries by default on unspecified code which still requires information for the compiler

@MinerMinerMain Great explanation!
I just have two small comments to clarify a couple of points:

  1. Instead of “ignoring” @globalActor, it’s worth noting that it can be used for things like database queues, shared services, or global synchronization contexts — so it's more than just a singleton indicator.
  2. For @concurrent, it might help to say that it marks a function or closure as able to execute concurrently. Callers must therefore treat it as potentially running on a different actor/isolation domain.