how I can call es request with distinct values in swift?
This is my code:
let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate a
NSPredicate will allow you to search for specific values and retrieve only the data you need from core data:
var StoredResults = [NSManagedObject]()
func fetchRequest(docID : String ){
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
let request = NSFetchRequest(entityName: "EntityContainingDocID")
let predicate = NSPredicate(format:"docID == %@", docID)
request.predicate = predicate
do {
let results =
try managedContext.executeFetchRequest(request)
StoredResults = results as! [NSManagedObject]
} catch let error as NSError {
print(" error executing fetchrequest ", error)
}
}
In this example we are only looking to return specific values matching a string in the "docID" column but NSPredicate is a handy way of building SQL-like queries into your code and is pretty flexible.