I prepare an app to migrate from ObservableObject to Observable, from EnvironmentObject to Environment(MyClass.self) and so so forth.
That works OK, very simple.
But, that forces to run on macOS 14 or more recent.
So I would like to have it conditionally, such as:
- if macOS 14 available
@Environment(ActiveConfiguration.self) var activeConfiguration: ActiveConfiguration
- otherwise
@EnvironmentObject var activeConfiguration: ActiveConfiguration
The same for the class declaration:
- if macOS 14 available
@Observable class ActiveConfiguration {
var config = Configuration()
}
- otherwise
class ActiveConfiguration : ObservableObject {
@Published var config = Configuration()
}
Is there a way to achieve this (I understand it is not possible through extensions of Macros, as we can do for modifiers) ?
Could I define 2 classes for ActiveConfiguration, but then what about @Environment ?