Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Last active June 17, 2019 08:36
Show Gist options
  • Select an option

  • Save AppleCEO/833f1c88766555c95f37e1d29c5ee2d6 to your computer and use it in GitHub Desktop.

Select an option

Save AppleCEO/833f1c88766555c95f37e1d29c5ee2d6 to your computer and use it in GitHub Desktop.
Generic and Custom Operators Swift Example
protocol Multipleiable {
static func * (lhs: Self, rhs: Self) -> Self
}
extension Int: Multipleiable {}
extension Double: Multipleiable {}
infix operator ** : MultiplicationPrecedence
func **<T> (lhs: T, rhs: T) -> T where T: Multipleiable {
return lhs * rhs
}
3 ** 4
// result : 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment