I'm passing around a Binding<T>, where T is numeric value types that NSNumber can handle/support. I need to know if its wrappedValue is signed numeric.
This doesn't work:
extension Binding {
var isSignedNumeric: Bool {
wrappedValue is SignedNumeric. // error: SignedNumeric has `Self` or PAT
}
}
I'm dong this now:
extension Binding {
var isSignedNumeric: Bool {
wrappedValue is Double
|| wrappedValue is Float
|| wrappedValue is Int32
|| wrappedValue is Int
|| wrappedValue is Int64
|| wrappedValue is Int16
}
}
with .keyboardType(.numberPad) attached to the TextField for entering numbers only. The .numberPad keyboard only has numbers 0-9 and delete and nothing else. I'm adding a keyboard toolbar to allow entering negative value only when the type is signed.
I have access to the binding of the TextField.
T can only be the types NSNumber can handle excluding Bool and Char, these:
I don't know how to constrain T to only these, so I do this T: Numeric but Numeric is not exactly the type above. Or T totally unconstrained, like the TextField.init above.
protocol NSNumberConvertible { }
protocol SignedNSNumberConvertible: NSNumberConvertible { }
protocol UnsignedNSNumberConvertible: NSNumberConvertible { }
// can do this now
... wrappedValue is SignedNSNumberConvertible ...