ГМ
Size: a a a
ГМ
ГМ
ГМ
ИК
ИК
id = 0
let defaults = UserDefaults.standard
func showHide(_ action: Bool){
buttonDec.isHidden = action
countCell.isHidden = action
}
func saveCount(_ countDish: Int) {
countCell.text = String(countDish)
defaults.set(countDish, forKey: String(id))
}
func configure(with basket: Welcome, andWith image: UIImage) {
self.id = basket.id!
self.titleCell.text = basket.name
self.subtitleCell.text = basket.description
self.priceCell.text = "\(basket.price ?? 0) ₽"
self.imageCell.image = image
if defaults.integer(forKey: String(id)) > 0 {
self.countCell.text = String(defaults.integer(forKey: String(id)))
showHide(false)
} else {
showHide(true)
}
}
@IBAction@IBAction func pressedButtonInc(_ sender: UIButton) {
let count = Int(countCell.text!)! + 1
saveCount(count)
showHide(false)
}
@IBAction@IBAction func pressedButtonDec(_ sender: UIButton) {
let count = Int(countCell.text!)! - 1
saveCount(count)
if count == 0 {
showHide(true)
}
}ИК
UserDefaults где писать?ИК
count = (Int(countCell.text!) ?? 0) + 1 ИК
ИК
count = 0
@IBAction@IBAction func pressedButtonInc(_ sender: UIButton) {
count = count + 1
saveCount(count)
showHide(false)
}