Creating individual list of favorites from a larger set of MapKit annotations

(Trigger alert: Post does not contain any code).

Beginner programmer here.

I am working on an app in Swift, it is going fine, considering my lack of experience and knowledge. But there is one feature I can’t figure out how to approach.

Essentially, I’m making a MapKit-based app with a significant number of locations, from which the user can tag some locations as a favorite, for easy access. (The app will do more, but this is the part which has left me wondering about the approach). I.e. the user can mark one of my pre-determined annotations as a favorite, he cannot create his own annotations.

I want to implement two things that are related, but I don’t know how to make them work together:

  1. Store thousands of MapKit annotations and populate a MapView and a UITableView with the full list. I’m currently storing the annotations in GeoJSON, but could also do it in Core Data, Realm, or another way, depending on what works best with point 2 below. It is a simple struct, only containing longitude, latitude, title, web address and one or two more Strings. The MapView scans the GeoJSON and populates the map with all annotations.

I will curate this database of annotations, which will be stored in the app as a GeoJSON/Core Data/Realm/whatever works best model. It will be updated once or twice a year, as annotations are deleted and added. Nothing will live on a server, everyting is in the app.

But I also want to:

  1. Let every user, drawing on the full list in point 1 above, create his own list of favorites — e.g. out of 1000 records, the user tags five as personal favorites.

Let’s say Jack downloads my app, and the app at that point has ten records/annotations: Restaurant 1, Restaurant 2…Restaurant 10. (It’s not a restaurant app, but the premise is the same). A map shows all 10 restaurants, and they also show up in a table. (All of this I’ll be able to do with GeoJSON and Core Data, and I guess I’ll be able to figure it out in Realm as well if that’s a better solution.)

Jack adds Restaurant 4 and 7 to his own list of favorites for easy access, and these two Restaurants show up in his «Favorites» UITableView.

Six months after Jack downloaded the app and chose his favorites, I update the app. Restaurant 7 has recently gone out of business, and a new Restaurant 11 has opened. I remove Restaurant 7 and add Restaurant 11 to my full list of Restaurants, and push the update out.

Now here is the challenge:

Jack still has Restaurant 7 stored in his list of favorites. So I need to have his favorites list/model check with the full list of restaurants every time the app is updated, and delete any object that he has favorited that no longer is present in the full list. In this case, Restaurant 7 should be removed from both the full list (which I will take care of) and from his personal favorites list, and no longer show up in his Favorites UITableView (which I am wondering how to do).

In my mind, I assume need two databases/models/data stores:

  1. One full list of annotations, which is the same for every user with the same version of the app. Every now and then I will push out a new version of this model, with app updates. With each update, some records are added, some modified (maybe a new street address), and some are deleted.

  2. Every user’s individual list of favorites. These favorites are drawn from the full list in point 1 above.

I know I’ll be able to make point 1 work, but I can’t wrap my head around point 2, how to have every user’s unique list of favorites «reach back» to the full list, check for changes to any records that are also saved in the favorites list, and reflect those changes. The one way I can sort of imagine is to assign every record in the full list an ID number, which is duplicated to the list of favorites, and then have the app check if that ID number still exists in the full list. If it does not, that Restaurant is deleted from the user’s personal favorites.

Is this possible (and «easy» to implement) with Core Data/Realm, or should I look at another approach? Is Core Data/Realm overkill for this feature - should the full list remain in Core Data/Realm or even GeoJSON, but favorites be created in a lighter and easier way?

Grateful for any tips on how to approach this.

@frostbite Thanks very much for your question!

What I would suggest is to have one table in Core Data, and simply have a column as favourites. Each object or row can have a default value of false. Once a user marks a particular restaurant to be a favourite, then this value is set to true, and for a user to simply display a list of his/her favourites, simply do a search where that column (e.g. favourites == true).

With respect to the issue of updating this list, you could provide an alert that states something to the effect (“Oops, this restaurant no longer exists. Would you like to delete it from your favourites?” Yes/No). Yes, would trigger a CoreData call to delete the value from the favourites column, No would allow the user to keep that value, but would still trigger the alert the next time. Just a thought.

I hope this helps!

All the best.

Thank you @syedfa. I could probably make this work, initially. What I do not understand is this:

Say I ship my version 1.0 with a Core Data model of restaurants, and a favourites column.

When I ship version 2.0 with an updated list of restaurants, will not every user’s list of favourites be overwritten by the favourites column in the Core Data model that is included with the app?

This topic was automatically closed after 166 days. New replies are no longer allowed.