我有一个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()
}
}
}
答案 0 :(得分:3)
这样做:
theMinutes = theMinutes - 20
或者(像@vadian提醒):
theMinutes -= 20
答案 1 :(得分:0)
或只是添加等号
theMinutes -= 20