Introduction

You can also create new operators.

You need to first define the type of operator, which can be infix, postfix, or prefix :

infix operator * 

Then, as with the custom + operator, you need to write the code for the function:

func *(left  : Vector2D, right: Vector2D) -> Vector2D { 
    let result = Vector2D(x: left.x * right.x, y: left.y * right.y) 

    return result 
} 

And now you can use it:

first * second // (x: 6, y: 2) 

Related Topic