SkillAgentSearch skills...

ProxyMacro

Swift macro that proxies a value from one object to another.

Install / Use

/learn @simonbs/ProxyMacro
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

ProxyMacro

Swift macro that proxies a property from one object to another.

final class MyObj {
    private final class StateStore {
      var number = 42
    }

    @Proxy(\Self.stateStore.number)
    var number: Int

    private let stateStore = StateStore()
}

This is useful when state needs to be kept in sync between multiple objects but we do not want to forward the state using willSet/didSet. In this case we pass the state store to the children instead. We can still expose the number property on MyObj and any reads and writes will be forwarded to the number propety on StateStore.

final class MyObj {
    private final class StateStore {
      var number = 42
    }

    @Proxy(\Self.stateStore.number)
    var number: Int

    private let stateStore = StateStore()
    private lazy var childA = Child(stateStore: stateStore)
    private lazy var childB = Child(stateStore: stateStore)
}

final class Child {
    private let stateStore: StateStore

    init(stateStore: StateStore) {
        self.stateStore = stateStore
    }
}
View on GitHub
GitHub Stars14
CategoryDevelopment
Updated4mo ago
Forks3

Languages

Swift

Security Score

77/100

Audited on Nov 20, 2025

No findings