jeudi 4 octobre 2018

Every time I click the button it only adds 50 increments,

When I'm on the simulator and click the button it keeps adding 50. I think it may not be saving "latestTerminationDate", or maybe not pulling it. Thank you for any help

@IBOutlet weak var coalRunButton: UIButton! var coalMayham = 1

@IBAction func coalRunButton(_ sender: Any) {
if  let buttonPress = UserDefaults.standard.object(forKey:  "buttonPress") as? Date,
        let terminationDate = UserDefaults.standard.object(forKey: "latestTerminationDate") as? Date
   {var terminationDuration = buttonPress.timeIntervalSince(terminationDate)
    if terminationDuration >= 86400 {  _ = 86400
        do { UserDefaults.standard.set(Date(), forKey: "latestTerminationDate")
             UserDefaults.standard.synchronize()
            let dailyCoalAccumulate  = ((Int(terminationDuration)) * coalMayham) + Int(coalPile.text!)!
            coalPile.text = String(dailyCoalAccumulate)
            UserDefaults.standard.set(Data(), forKey:"totalCoal")}
        } else  {
        terminationDuration =  50

        UserDefaults.standard.set(Date(), forKey: "latestTerminationDate")
          UserDefaults.standard.synchronize()

            let dailyCoalAccumulate  = ((Int(terminationDuration)) * coalMayham) + Int(coalPile.text!)!
            coalPile.text = String(dailyCoalAccumulate)
            UserDefaults.standard.set(Data(), forKey:"totalCoal")

    }} else {
    let terminationDuration = 40

    UserDefaults.standard.set(Date(), forKey: "latestTerminationDate")
    UserDefaults.standard.synchronize()

    let dailyCoalAccumulate  = ((Int(terminationDuration)) * coalMayham) + Int(coalPile.text!)!
    coalPile.text = String(dailyCoalAccumulate)
    UserDefaults.standard.set(Data(), forKey:"totalCoal")
    }
}

Aucun commentaire:

Enregistrer un commentaire