J'ai un Int que je suis en train de soustraire, mais je suis confus quant à pourquoi le code est couru, mais l'Int ne fait pas la soustraction, y at-il quelque chose que je manque?Soustrayant de 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()
}
}
}
S'il vous plaît lire sur la différence entre valueForKey et objectForKey. Vous ne voulez vraiment pas vraiment utiliser valueForKey ici. – gnasher729