Oh I see now, thanks a lot for you help!
I find it a lot more ergonomic though to just pass a Binding<String?>
public extension Client {
static func live(
userDefaultsKey: String,
userDefaults: @escaping() -> UserDefaults
) -> Self {
live(
sessionKeychainKey: Binding<String?>(
get: { userDefaults().string(forKey: userDefaultsKey) },
set: { userDefaults().set($0, forKey: userDefaultsKey) }
)
)
}
static func live(
sessionKeychainKey keychainKey: Binding<String?> = .constant(nil)
) -> Self {
live(
I can declare my variables inside unamed closures, etc... and create those binding on the fly:
let client = IGClient.live(
session: Binding<IGClientLiveSession?>(
get: { session },
set: { session = $0 }
)
)
It doesn't seem to be possible to pass a writable key path for a variable that was declared inside an unamed closure or inside a playground. Or am I missing something