Gold Challenge - My simple solution :-)

The way I solved this is make the itemStore static:

static var itemStore: ItemStore!

Then, I added this property in the ItemStore class:

 let notification = Notification(name: Notification.Name(rawValue: "itemsChanged"))

I made the itemStore post the notification when it went to the background and saved the data. That is, I placed the code below at the end of the “do” section of the saveChanges() function:

NotificationCenter.default.post(notification)

Finally, I added this code at the end of the modified initializer:

let notificationCenter = NotificationCenter.default
    notificationCenter.addObserver(self, selector: #selector(reTable), name: Notification.Name(rawValue: "itemsChanged"), object: nil)

Please do not create a new initializer. You have already modified an initializer:

required init?(coder aDecoder: NSCoder) {...}

Remember that? That is where I inserted the code.
I am not sure if this is the best solution, but seems to work. I would love to hear your thoughts and opinions.
Thank you.

And by the way, for the part about updating one scene when the other is updated, I got a hint from @fabfe31’s method. Thanks.

1 Like