The code generated by the Entry macro depends on the extension in which the macro is applied.
extension EnvironmentValues {
@Entry var value: Int = 42
}
expands to
extension EnvironmentValues {
var value: Int {
get {
self[__Key_value.self]
}
set {
self[__Key_value.self] = newValue
}
}
private struct __Key_value: SwiftUICore.EnvironmentKey {
typealias Value = Int
static var defaultValue: Value { 42 }
}
}
and
extension ContainerValues {
@Entry var value: Int = 42
}
expands to
extension ContainerValues {
var value: Int {
get {
self[__Key_value.self]
}
set {
self[__Key_value.self] = newValue
}
}
private struct __Key_value: SwiftUI.ContainerValueKey {
typealias Value = Int
static var defaultValue: Value { 42 }
}
}
How does the macro get information about the extension?