title: How do I make a custom validation (for uniqueness) in Core Data?
body: <p>I have an entity in Core Data which has an attribute that needs to be unique. There's no way to set this in the visual interface. I assume I need to create a custom class that inherits from NSManagedObject and then write my own validation method.</p>
  
  <p>I successfully created the custom class by selecting the entities in the visual editor and choosing File -> New -> New File -> NSManagedObject subclass. I use this to add creation timestamps, so I know it works.</p>
  
  <p>But now what? Which methods do I need?</p>
  
  <p>The <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html" rel="nofollow noreferrer">NSManagedObject reference guide</a> tells me to "implement methods of the form validate:error:" but doesn't provide an example.</p>
  
  <p>Similar questions <a href="https://stackoverflow.com/questions/2415537/core-data-uniqueness">here</a> and <a href="https://stackoverflow.com/questions/3270164/core-data-how-to-validate-the-uniqueness-of-an-attribute-within-the-scope-of">here</a>, but I need a bit more help. </p>
  
  <p>A complete example would be awesome, but any help is much appreciated.</p>