ios - To fetch unique Attribute/Column values in Core Data -


i have entity calculatorproduct attributes 'id','brand','category', 'mrp' want fetch values of 'category' column/attribute

  let context = databasecontroller.getcontext()     let fetchrequest:nsfetchrequest<calculatorproduct> = calculatorproduct.fetchrequest()      fetchrequest.propertiestofetch = ["category"]      fetchrequest.returnsdistinctresults = true     do{          let result = try context.fetch(fetchrequest)           print("array db \(string(describing: result.count))")         print("array db \(string(describing: result))")          val in result{              print("\(string(describing: val.category))")         }      }     catch{          print("error in fetching is\(error)")     } 

try following:

let context = databasecontroller.getcontext() let fetchrequest:nsfetchrequest<calculatorproduct> = calculatorproduct.fetchrequest() fetchrequest.propertiestofetch = ["category"] fetchrequest.returnsdistinctresults = true fetchrequest.resulttype = .dictionaryresulttype {     let result = try context.fetch(fetchrequest) as! [[string:any]]      print("array db \(string(describing: result.count))")     print("array db \(string(describing: result))")      val in result{         print("\(string(describing: val["category"]))")     } } catch{     print("error in fetching is\(error)") } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -