> On Apr 20, 2018, at 1:15 AM, Glen Huang <hey...@gmail.com> wrote: > > I have an app where user can edit data and save to my server. I wonder what’s > the best way to update affected view controllers in the navigation stack?
If I were to give a literal answer to your question, I'd suggest a callback method (either as a closure property on the child VC or a classic delegation) by which the parent VC can be notified by the child of relevant change. However, it sounds like you might be well off to re-frame your question more generally as "what's the best way to keep my views in sync with my data model". The case you described (a detail VC on a nav stack) is merely one such manifestation. > 1. Load all data (the list of recipes comes with full details) into Core > Data. Basically I create a local replica of my server data and use a > NSFetchedResultsController to fetch all ingredients sectioned by recipes. And > then show the array count in each section for each cell. That sounds like a reasonable approach. You need to model your data locally somehow; Core Data provides a somewhat decent way to do it. I'm also fond of Couchbase Lite. Especially if you are dealing in various unstructured data, it might be well suited. It provides change-listener callbacks in similar way. The server-side setup would no doubt be an undertaking compared to what you currently have though. > 2. Server returns tailored data for each view controller. For example, for > the recipe list view controller, the server returns a list of recipe > containing only names and ingredients counts. For the recipe detail view > controller, the server returns details just for the corresponding recipe, and > in the ingredient view controller, the server returns a list of ingredients > just for that recipe, basically every view controller needs to make a request > to my server to get its data. That does not sounds like a good idea. In essence you then have no local data persistence, and the remote server works like a database over a very slow link. The app would never work offline, and any trivial architectural changes in the client would need to be also made on the server. b _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com