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)
}
}