-3
let Rating = self.currentPerson.Rating // This is a NSNumber

Rating -= 1

What I'm trying to do, is to take an x value from the Rating, and then print the new value of Rating.

How do I do this properly?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Victor
  • 1,603
  • 4
  • 17
  • 24
  • This doesn't compile: *binary operator '-=' cannot be applied to operands of type 'NSNumber' and 'Int'* – vadian Jan 02 '17 at 13:08

1 Answers1

2

To perform this operation in the way you wish you need to write your own function for handling it:

infix operator -=

func -=(lhs:inout NSNumber, rhs:Double) {
    lhs = NSNumber(value: lhs.doubleValue - rhs)
}

You also need to use a variable rather than a constant in your implementation:

var Rating = self.currentPerson.Rating // This is a NSNumber

Rating -= 1

So that the value can be changed.

sketchyTech
  • 5,746
  • 1
  • 33
  • 56