Search code examples
swiftparse-platformpfquery

How to retrieve a specific Column From Parse with swift?


I have a Array column in my parse Class called "serviceHistory". Its in JSON format. I am having trouble querying just this column for all my parse objects(pool Accounts).

With This code i can print out each object, but i am having trouble accessing just the service History column.

var query = PFQuery(className:"PoolAccount")
query.selectKeys(["serviceHistory"])
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

  if let objects = objects as? [PFObject] {

    self.serviceHistory = objects
    print("these are the selectedKeys \(objects)")

   //THIS PRINTS THE WHOLE OBJECT, AND NOT JUST THE SELECTED KEY."serviceHistory"

enter image description here

I am looking to print out just the service History and can't find the right query to do it...Its an array of JSONS for Each Object.

enter image description here

this is what I'm looking for it to print out..Each Pfobject has an array of JSONs attached to it. So i think i possibly need an array of arrays to put it in? [[PFObject]]? thanks in advance.


Solution

  • The query will always return an array of PFObject, you can't limit to a single column only. You can post process the objects to extract an array containing only that column content for each object:

    ... = objects.valueForKey("selectedKeys")