I’m kind of stuck on what I would assume is a simple solution and I just can’t figure out what to do.
I’m basically creating an expenses application for iOS and I’ve gotten to the point where I need to add up all the total expenses from my UITableView list.
private var items:[Shoe] =  private var appDelegate = UIApplication.shared.delegate as! AppDelegate private var managedContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext // Start of calculating the gain or loss for the individual item let buyDouble: Double? = Double(buyToSave) let sellDouble: Double? = Double(sellToSave) let feeDouble: Double? = Double(feeToSave) let feeInt = 1-(feeDouble!/100) let profit = (feeInt*sellDouble!) - buyDouble! let profitNSNumb = profit as NSNumber let profitString = currencyFormatter.string(from: profitNSNumb) let shoe = Shoe(entity: Shoe.entity(), insertInto: self.managedContext) shoe.name = nameToSave shoe.buyPrice = buyToSave shoe.sellPrice = sellToSave shoe.size = sizeToSave shoe.fee = feeToSave shoe.profitLoss = profitString shoe.quantity = Int16(shoeQuantity) shoe.sum = shoe.sum + profit // Save the data self.appDelegate.saveContext() // Reloads the UITableView self.shoeList.reloadData() self.viewDidLoad()
I believe my logic is correct right? Im not sure why I keep start at $0 every time I quit my application and open it back up again?
Total Expense: $350
Then when I close the app and start it up again:
Total Expense: $350 <---- I want it to start at $350 and not $0