从 Int 中减去
Subtracting from Int
我有一个 Int,我想从中减去,但我很困惑为什么代码得到 运行,但 Int 不做减法,是不是我遗漏了什么?
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()
}
}
}
这样做:
theMinutes = theMinutes - 20
或者(就像@vadian 提醒的那样):
theMinutes -= 20
或者只加等号
theMinutes -= 20
我有一个 Int,我想从中减去,但我很困惑为什么代码得到 运行,但 Int 不做减法,是不是我遗漏了什么?
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()
}
}
}
这样做:
theMinutes = theMinutes - 20
或者(就像@vadian 提醒的那样):
theMinutes -= 20
或者只加等号
theMinutes -= 20