ios - Swift: Keeping copies of data consistent across multiple viewControllers & Arrays -


i'm building app similar functionality instagram, , i'm not sure how best structure data tableviews , collectionviews. let's go on views first.

  1. newsfeed vc own array of posts (newest information)
  2. group vc own array of posts (group specific information there ~30 different groups)
  3. search vc own array of posts (search result specific)
  4. expanded vc displays post in full screen

the problem user can like/comment on post in group/search vc might in newsfeed vc or vice versa.

currently passing index vc vc , modifying data in array. has lead few problem end looping on other arrays sync likes/comments , have refresh tableview user change in present locally.

i'm wondering if there more efficient/logical way store of data. need group data separate newsfeed data, , user can change group whenever want see other posts.

i've never used core data, i'm open anything. ideally, i'd able store of information in 1 place single copy of every post. right if post in group & newsfeed have 2 copies, 1 in each corresponding array. need posts in order (they have timestamp , unique ids firebase already).

you can use core data save posts view controllers based on unique id, avoid duplicate records.

when pull data server, each time need save in core data.

after that, on each control, need right predicate, should match query while fetching data particular view controller.

by using predicate, fetch data core data, , use data display in view controller.

to reflect changes in each view controller, can fetch data core data in viewwillappear , reload table or can use nsfetchedresultscontroller keep data updated.

hope help.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -