title: Swift: Best way to avoid creating duplicate entries in CoreData
body: <p>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).</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>I am using the basic code to instantiate the Match Info objects:</p>
  
  <pre><code>let newManagedObject = NSEntityDescription.insertNewObjectForEntityForName(entity.name!, inManagedObjectContext: context)
  </code></pre>
  
  <p>Thanks!</p>