Reputation: 368
I have a UITableView
in which i am populating data from core data. The TableViewCell
consists of some labels and a favourite button. I want that, when user clicks the button
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 button
. 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.
Upvotes: 2
Views: 2656
Reputation: 11555
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
...
Upvotes: 1