Thank you! This solve my problem:
protocol NSNumberConvertible { }
protocol SignedNSNumberConvertible: NSNumberConvertible { }
protocol UnsignedNSNumberConvertible: NSNumberConvertible { }
// can do this now
... wrappedValue is SignedNSNumberConvertible ...
this also solve my other problem
For learning, I took your code and changed a little to make it work for test if is SignNumeric
:
protocol SignedNumericConformanceMarker {}
enum SignedNumericMarker<T> {}
extension SignedNumericMarker: SignedNumericConformanceMarker where T: SignedNumeric {}
func isSignedNumericType<T>(_ t: T.Type) -> Bool {
return SignedNumericMarker<T>.self is SignedNumericConformanceMarker.Type
}
func isSignedNumeric<T>(_ t: T) -> Bool {
return isSignedNumericType(T.self)
}
let u: UInt = 0
let i = 0
print("isSignedNumeric(u)", isSignedNumeric(u)) // print: isSignedNumeric(u) false
print("isSignedNumeric(i)", isSignedNumeric(i)) // print: isSignedNumeric(i) true
// make it a little fluent
extension Numeric {
var isSigned: Bool {
isSignedNumeric(self)
}
}
print("u.isSigned", u.isSigned)
print("i.isSigned", i.isSigned)
very interesting how you build thing up and then go from T
to T.Type
. I can never be able to come up with code like this.