* already defined, initially, as a binary infix operator in Swift:
infix operator * { associativity left precedence 150 }
Therefore, any function of the form func * (... will overload this binary infix operator. On the other hand, if you try to use the * operator as a prefix of a unary operator, you will get a descriptive error that " * not a prefix of a unary operator", just since * does not exist initially as a prefix operator.
Of course, you can define your own prefix operator * :
prefix operator * { } prefix func * (rhs: Int) -> Int { return rhs*rhs } var a : Int = 2 var b : Int = *a
To wrap this up: some operators exist initially in Swift both as prefix and infix operators, for example. -
infix operator - { associativity left precedence 140 } prefix operator - { } let a : Int = 2 - 1
while others, such as * , are simply (originally) used as an infix operator.
Also note that if you want to define your own custom infix operators, their resolved names are limited as follows:
User statements may begin with one of the ASCII characters /, =, -, +,!, *,%, <,>, &, |, ^ ,? or ~ or one of the Unicode characters defined in the grammar below (which include characters from Math operators, various characters and Unicode block dingbats, among others). After the first character combining Unicode characters are also allowed.
From Language Reference - Lexical Structure .