ios - Is it possible to overload += operator in Swift? -


For example CGFloat is possible for overload + = operator in swift to accept the argument ? if so, how?

My attitude (below) does not work.

  Infix operator + = {affiliation left priority 140} public func + = (left left: CGFloat, right: CGFloat) {left = left + right}  

(edit) Important:

The upward coding approach actually works. Please explain why I thought it was not for clarification.

I'm sorry, my bad operator + = to CGFloat argument There is no need to be overloaded because Swift contains such surcharges. I was trying to do this

  let's go: CGFloat = 1.5 a + = CGFloat (2.1)  

This failed because I put the let and the error displayed by XCode confused me.

And of course, works for overloading operators in my basic question (such as).

  Infix operator + = {Affiliate left priority 140} Public func + = (left: CGFloat, right: CGFloat) {left = left + right}  

Please feel free to vote to stop it.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -