Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Operator Overloading in Swift Tutorial

Learn how to extend operators for new types or create entirely new operators in this new Swift tutorial!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2271-operator-overloading-in-swift-tutorial

How do I make this overloading of + work in Swift 4? When I try this, Xcode complains about “Ambiguous use of operator ‘+’”.

func +(left: Int, right: Int) -> Int {
    return left - right;
}

print(2 + 1); // should result in 1

@jkantner This tutorial is more than six months old, so questions are no longer supported at the moment for it. Please check out the tutorial’s updated version when you get a chance:

Thank you! :]