【发布时间】:2015-12-07 07:40:02
【问题描述】:
我有一个 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()
}
}
}
【问题讨论】:
-
请阅读 valueForKey 和 objectForKey 之间的区别。你真的,真的不想在这里使用 valueForKey。
标签: ios swift int subtraction