Suppose a table named TBL_person has 4 columns and I want to fetch data of only id and name column
In SQL I can do it like this:
SELECT id, name FROM TBL_person ORDER BY id ASC
But what to do in SWIFT?
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let moContext:NSManagedObjectContext = appDel.managedObjectContext
let fetchRequest = NSFetchRequest()
let entityDescription = NSEntityDescription.entityForName("TBL_person", inManagedObjectContext: moContext)
fetchRequest.entity = entityDescription
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true)]
do {
let personList = try moContext.executeFetchRequest(fetchRequest) as! [ModelPerson]
print("test------", personList.count)
} catch {
let fetchError = error as NSError
print(fetchError)
}

propertiesToFetch...