SwiftExtension // Make AppProperty bindable.

This commit is contained in:
ShikiSuen 2022-12-22 00:31:49 +08:00
parent cf5170cced
commit c11e08f33d
2 changed files with 17 additions and 1 deletions

View File

@ -115,7 +115,7 @@ extension Bool {
} }
} }
// MARK: - Property wrapper // MARK: - Property Wrapper
// Ref: https://www.avanderlee.com/swift/property-wrappers/ // Ref: https://www.avanderlee.com/swift/property-wrappers/

View File

@ -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)
}
)
}
}