I am php web developer. I have learnt ios swift recently. I am trying to fetch the records from core data and group the records based on one column or more appropriately bas
Finally I could resolved the issue. Though I dont have knowledge in objective C, I have searched for the same issue in objective C and got the idea to resolve my problem in Swift. It could help someone who might be facing the same problem, so im sharing my solution here.
The issue was propertiesToGroupBy must contain all the elements which are to be fetched by propertiesToFetch. For clarity I am pasting those two lines of code separately here:
request.propertiesToGroupBy = ["order_num","cust_name"]
request.propertiesToFetch = ["order_num","cust_name"]
Observe the above lines of code have both elements(attributes) order_num and cust_name. (this is merely an example from my code. but we can add as many elements we want)
Here is the full code solution for my above question:
var context : NSManagedObjectContext = appdel.managedObjectContext!
var request = NSFetchRequest(entityName: "TblOrders")
request.returnsObjectsAsFaults = false
request.propertiesToGroupBy = ["order_num","cust_name"]
request.propertiesToFetch = ["order_num","cust_name"]
request.resultType = .DictionaryResultType
context.executeFetchRequest(request, error: nil)!
var res = context.executeFetchRequest(request, error: nil)!
var results = res as NSArray
println(results)