sunny k sunny k - 1 year ago 70
Swift Question

Add to favourites function [swift]

I have a

in which i am populating data from core data. The
consists of some labels and a favourite button. I want that, when user clicks the
the entire cell is added to a different favourite table view controller class, which can be accessed from the Favourite tab.
Just like in stock iphone "Phone" app. When the user adds a contact to favorites it is visible under the favourite tab.
How can i achieve this in swift ?
Please guide me and point me in the right direction.

I was thinking of something like, adding the cell data to a different core data model on the click of the
. Then using this model to populate the cells in favourite table view controller class.
But i am new to swift and dont know how to implement this idea. Any kind of help will be much appreciated.

Answer Source

So you already have CoreData entity that you use to populate the table view. You could add a new attribute of type bool to it that indicates if the item is a favorite. Let's call it for example isFavorite. Then in your Favorite tab you use CoreData to populate the favorites table the same way as you populate your main table, but you create the CoreData query with a predicate isFavorite == true...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download