Cody Weaver Cody Weaver - 1 year ago 66
Swift Question

What protocols do all numbers conform to in Swift?

I am trying to figure out what protocols in Swift make it so I have a function that only takes Numbers. I want to be able to pass

, pretty much any combination of Numbers.

func takeNumbers(A: Protocol1, Protocol2, B: Protocol1, Protocol2) {


I just listed two protocols I don't know if it I need 1,2,3, etc.

Answer Source

Why not create your own protocol and extend each type to conform to it?

Further, you could use a protocol extension to implement a common method to get the value of each. For instance, you could return an int value from each by implementing switch logic on the type.

Also, you said Float twice.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download