Chandler De Angelis
Chandler De Angelis

Reputation: 2776

Swift could not find an overload for '+=' that accepts supplied arguments

I am using Swift, and I am trying to use the += assignment operator, but I am getting this error. Here is my code:

    var total = NSNumber.numberWithDouble(0.00)
    for exercise in exercises {
        total += exercise.duration
    }
    return total

the duration property of the exercise object is a NSNumber, so I don't see why I am not able to perform the assignment. Does anyone know why this is not working?

Upvotes: 0

Views: 191

Answers (1)

Catfish_Man
Catfish_Man

Reputation: 41831

NSNumber doesn't have a += operator. I would suggest using Double instead, then converting to NSNumber after the loop if you really need an NSNumber.

Upvotes: 3

Related Questions