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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -