SwiftExtension // Make AppProperty bindable.
This commit is contained in:
parent
cf5170cced
commit
c11e08f33d
|
@ -115,7 +115,7 @@ extension Bool {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Property wrapper
|
||||
// MARK: - Property Wrapper
|
||||
|
||||
// Ref: https://www.avanderlee.com/swift/property-wrappers/
|
||||
|
||||
|
|
|
@ -156,3 +156,19 @@ public struct TextEditorEX: NSViewRepresentable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Property Wrapper (Bindable Extension)
|
||||
|
||||
extension AppProperty {
|
||||
@available(macOS 10.15, *)
|
||||
public var projectedValue: Binding<Value> {
|
||||
.init(
|
||||
get: {
|
||||
container.object(forKey: key) as? Value ?? defaultValue
|
||||
},
|
||||
set: {
|
||||
container.set($0, forKey: key)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue