commit bdde64c537200d21d9789afaebcc92fcb53835f6
parent 50348b69d2373edde55289f01e7f10e83382ec97
Author: Marc Stibane <marc@taler.net>
Date: Sat, 6 Sep 2025 22:15:50 +0200
Binding+convert
Diffstat:
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/TalerWallet1/Helper/Binding+convert.swift b/TalerWallet1/Helper/Binding+convert.swift
@@ -0,0 +1,44 @@
+// MIT License
+// Copyright https://stackoverflow.com/users/168179/mark-a-donohoe
+// https://stackoverflow.com/questions/65736518/how-do-i-create-a-slider-in-swiftui-bound-to-an-int-type-property
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+// and associated documentation files (the "Software"), to deal in the Software without restriction,
+// including without limitation the rights to use, copy, modify, merge, publish, distribute,
+// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+import SwiftUI
+
+public extension Binding {
+
+ static func convert<TInt, TFloat>(_ intBinding: Binding<TInt>) -> Binding<TFloat>
+ where TInt: BinaryInteger,
+ TFloat: BinaryFloatingPoint{
+
+ Binding<TFloat> (
+ get: { TFloat(intBinding.wrappedValue) },
+ set: { intBinding.wrappedValue = TInt($0) }
+ )
+ }
+
+ static func convert<TFloat, TInt>(_ floatBinding: Binding<TFloat>) -> Binding<TInt>
+ where TFloat: BinaryFloatingPoint,
+ TInt: BinaryInteger {
+
+ Binding<TInt> (
+ get: { TInt(floatBinding.wrappedValue) },
+ set: { floatBinding.wrappedValue = TFloat($0) }
+ )
+ }
+}