I'm sending a string value from my vc2 to vc1 through UserDefaults
. But when I move back to vc1 from vc2 through back button the value doesn't update. I'm getting value in vc1 in viewWillAppear
method. But my value does not update. I navigate from vc1 to vc2 through push method.
This is how i stored the value in user default in vc2,
cartItems = cartItems + 1
print(cartItems)
let badgeCount = String(cartItems)
print(badgeCount)
let rightBarButton = self.navigationItem.rightBarButtonItem
let badge = String(badgeCount)
rightBarButton?.addBadge(text: badge)
UserDefaults.standard.set(badgeCount, forKey: "cartsItems")
UserDefaults.standard.synchronize()
and in vc1 i get like this in viewWillAppear delegate,
let count = UserDefaults.standard.string(forKey: "cartsItems")
print(count)
When i come back to vc1 from vc2 through back button value never update and when i call some other vc and than call again vc1 it gets update. How can i update value at that time?