I have an app that allows users to save favorites. I am using Core Data to store the favorites as managed objects. I have written some code to prevent the possibility of storing
Swift 3:
func isExist(id: Int) -> Bool { let fetchRequest = NSFetchRequest(entityName: myEntityName) fetchRequest.predicate = NSPredicate(format: "id = %d", argumentArray: id) let res = try! theContext.fetch(fetchRequest) return res.count > 0 ? true : false }