I have read SE-0411 Isolated default value expressions
@MainActor
public struct TextConfig {
public init(title: String = "") {
self.title = title
}
var title: String
}
@MainActor
struct BarItemConfigStruct {
var title: TextConfig
static func title(config: TextConfig = TextConfig()) -> BarItemConfigStruct {
return BarItemConfigStruct(title: config)
}
}
@MainActor
public enum BarItemConfigEnum {
case title(config: TextConfig = TextConfig()) //error: Main actor-isolated default value in a nonisolated context
}
However, I encountered an error with the above code.
I can roughly guess the reason:
the static structure of the enum causes TextConfig
not to guarantee evaluation of default values within the main actor isolation.
But I think this should be supported, after all, TextConfig
is isolated by the main actor.
Please point out my mistakes, I am willing to learn more details.
ENV: Xcode 16.0 (16A242d)