[swift-users] Detect if a generic type is numeric

V T not_my_name+swift at mailbox.org
Thu Sep 21 14:58:09 CDT 2017


Hi there!

Is there a best way to check if a given type conforms to numeric protocol (Integer or FP) at runtime?

func checkNumeric<T>(_ value: T) {
	/* return true if vaiue is Integer or FP */
	/* this will not compile: */
	if value is Numeric {
		
	}
}
 
Best regards!

VT


More information about the swift-users mailing list