You use a filter on the array:
func getItems() -> [Item]
{
return itemStore.allItems.filter { (displayFavoritesOnly == false) || $0.favorite }
}
If the filter button is selected, the filter returns only favorited items; if the button is not selected it returns a copy of itemStore. Everywhere in itemViewController where you access itemStore directly, you replace that with a call to this filter function:
let item = getItems()[indexPath.row]
(The only exception would be when you’re adding a new item; you need to add the item to the actual itemStore, not to the filter).
Obviously you’ll need to tailor this depending on how you handled sections. But this should get you started.