Re: Best strategy to update view controllers in navigation stack after users edit data
Re: Best strategy to update view controllers in navigation stack after users edit data
- Subject: Re: Best strategy to update view controllers in navigation stack after users edit data
- From: Glen Huang <email@hidden>
- Date: Sat, 21 Apr 2018 17:24:55 +0800
Thanks for the reply, Ben.
> I'd suggest a callback method
I thought about this approach, but it has the drawback that child view
controller needs to be aware of all other view controllers that it needs to
notify, when the hierarchy of view controllers is complex, finding the correct
ones isn’t that easy.
> I'm also fond of Couchbase Lite
Thanks for brining Couchbase Lite to my attention. I wonder if it can easily
handle circular data structure (or many to many relationship to be precise),
that’s one of the benefits Core Data offers that I rely on heavily.
> any trivial architectural changes in the client would need to be also made on
> the server.
Good point.
> On Apr 21, 2018, at 5:46 AM, Ben Kennedy <email@hidden> wrote:
>
>> On Apr 20, 2018, at 1:15 AM, Glen Huang <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden