3

I am writing a simple iOS app that shows historic soccer scores. At present, I am trying to stop duplicate "match info" objects appearing in the table view of historic results (my code pulls match info objects based on the date of the game matching today's date going back X number of years. A bit like Timehop).

This works fine, however there is no check to see if a match info object already exists in the context. A duplicate will be created if the user re-visits the Settings menu to choose other teams' results to see and DOES NOT deselect a previously chosen team.

What is the easiest way to avoid creating the duplicate altogether if my managed object context already contains an object with the new object's data?

I am using the basic code to instantiate the Match Info objects:

let newManagedObject = NSEntityDescription.insertNewObjectForEntityForName(entity.name!, inManagedObjectContext: context)

Thanks!

SiHa
  • 7,830
  • 13
  • 34
  • 43
d5automations
  • 419
  • 1
  • 6
  • 13
  • 1
    It's not an answer to your question. but I'd suggest to consider to give a try Realm DB. It's way easier to use and it has the rich number of query api. – ProblemSlover Nov 10 '15 at 13:19
  • You need to add a unique constraint. You can do it through UI of your xcode. Have a Look at the answer http://stackoverflow.com/a/32814593/1163224 – ProblemSlover Nov 10 '15 at 13:26

0 Answers0