You cannot query arbitrary properties of an NSManagedObject with a predicate for NSFetchRequest. This will only work for attributes defined in your entity.
NSManagedObjectContext has two ways to retrieve an object using NSManagedObjectID. The first throws an exception if the object does not exist in context:
managedObjectContext.objectWithID(objectID)
The second will fail, returning nil:
var error: NSError? if let object = managedObjectContext.existingObjectWithID(objectID, error: &error) { // do something with it } else { println("Can't find object \(error)") }
If you have a URI instead of NSManagedObjectID, you must first transfer it to NSManagedObjectID. To do this, use persistentStoreCoordinator:
let objectID = managedObjectContext.persistentStoreCoordinator!.managedObjectIDForURIRepresentation(uri)
source share