0

I have setup a Parse.com backend. In my iOS application I have connection with this backend and am able to retrieve the objects stored.

I want each specific object to be stored in an array. Let's say the objects where my Key:value is for example: Category = Coffeebars

For now I have written the following code:

let queryToGetBuildings = PFQuery(className: "Building")

queryToGetBuildings.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

if error == nil {
    for object in objects!{
         print("this is an object")
         print(object)
    }
 } else {
    print("something went wrong")
 }

Which returns each of my objects separate:

"this is an object"
<Building: 0x7f, objectId: yh, localId: (null)> {
    BottomText = "Opened from";
    BottomTextExtra = "05:00 until 22:00";
    Category = Coffeebars;
    MiddleText = "Suggestion:";
    MiddleTextExtra = "Apple and cinnamon";
    TimeToDestination = 5;
    TopText = Starbucks;
}

"this is an object"
<Building: 0xr, objectId: Xj, localId: (null)> {
    BottomText = "Fee per person (not for babies):";
    BottomTextExtra = "0.20";
    Category = Toilets;
    MiddleText = "Men - Women - Babies";
    MiddleTextExtra = " ";
    TimeToDestination = 5;
    TopText = "Bathroom 2 terminal A";
 }

"this is an object"
<Building: 0pr, objectId: 2q, localId: (null)> {
    BottomText = "Fee per person (not for babies):";
    BottomTextExtra = "0.20";
    Category = Toilets;
    MiddleText = "Men - Women";
    MiddleTextExtra = " ";
    TimeToDestination = 8;
    TopText = "Bathroom 3 terminal A";
}

My main question now is how can I print out (and add to a specific Array) all information for an object with Key:Value = Category:Toilets?

Thanks in advance

1
  • Do you know that Parse.com is going to be shutdown? Commented Apr 24, 2016 at 17:37

1 Answer 1

2

If I'm understanding you well, you are asking how to display fetched data.

First you should declare an array to hold fetched data:

var someData = [PFObject]()

inside your closure add this self.someData.append(object), now your code should look like this:

let queryToGetBuildings = PFQuery(className: "Building")

queryToGetBuildings.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

if error == nil {
    for object in objects!{
         print("this is an object")
         print(object)

         // Add this line
         self.someData.append(object)
    }
 } else {
    print("something went wrong")
 }

After you have fetched data it's time to display:

// if you are using tableView to display 
let thisData = someData[indexPath.row] 

let bottomText = thisData["columnName"] as? String
let bottomTextExtra = thisData["columnName"] as? String
let category = thisData["columnName"] as? SomeType
let middleText = thisData["columnName"] as? String
let middleTextExtra = thisData["columnName"] as? String
let timeToDestination = thisData["columnName"] as? NSNumber
let topText = thisData["columnName"] as? String
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.