Search code examples
iosswiftintsubtraction

Subtracting from Int


I have an Int I'm trying to subtract from, but I am confused as to why the code gets ran, but the Int doesnt do the subtraction, is there something I'm missing?

func calculateTime(theEmployee : Employee, thePunch : TimeClockPunchObj) {

    if thePunch.valueForKey("punchOutIn") as! String == "out" {

        let theLastPunchDate = self.lastPunch?.valueForKey("timePunched") as! NSDate
        var theMinutes = NSDate().minutesFrom(theLastPunchDate)
        print(lunchResult!)
        if (lunchResult!) {
            theMinutes - 20
        }
        print(theMinutes)
        let hours = String(format: "%.2f", (Double(theMinutes) / 60.00))
        print(hours)

        let timeCalc = TimePunchCalcObject()
        timeCalc.employee = theEmployee
        timeCalc.timePunchedIn = self.lastPunch?.valueForKey("timePunched") as! NSDate
        timeCalc.timePunchedOut = thePunch.valueForKey("timePunched") as! NSDate
        timeCalc.totalTime = Double(hours)!
        if Double(hours)! != 0.00 {
            timeCalc.saveInBackground()
        }
    }
}

Solution

  • Do this:

    theMinutes = theMinutes - 20
    

    Or (like @vadian reminded):

    theMinutes -= 20