methodcalls
methodcalls

Reputation: 61

PFObject to NSArray not working

I have a coordinate array in Parse that I am pulling and need to turn it into an NSArray of multiple coordinate values. However, when I pull the array from Parse, it acts as if there is only a single object in the entire array, while there is clearly more. I cannot figure out how to solve this issue anywhere.

Here's my code:

PFQuery *query = [PFQuery queryWithClassName:@"Buildings"];
[query getObjectWithId:@"Owuskh4h3a"];
// Attempt query
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded. Print success
        NSLog(@"Successfully retrieved %lu object(s).", (unsigned long)objects.count);

        // Scrape out the coordinate data and find the center
        for (PFObject *object in objects) {
            NSArray *parseCoordinateArray = [object valueForKey:@"coordinates"];
            NSLog(@"%@, %lu", parseCoordinateArray,[parseCoordinateArray count]);

        }
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

And here's what is outputted by NSLog:

2015-02-18 12:02:49.713 ParseTesting[1633:37337] (
    (
            (
        "-82.81646864992804",
        "40.08345434971258"
    ),
            (
        "-82.81645138320751",
        "40.08370572298874"
    ),
            (
        "-82.81598585230525",
        "40.08368703134467"
    ),
            (
        "-82.81600303520675",
        "40.0834356580685"
    ),
            (
        "-82.81646864992804",
        "40.08345434971258"
    )
)
), 1

As you can see, there are clearly five objects in this array, but Parse treats it as a single object. What is going on?

Upvotes: 0

Views: 304

Answers (1)

Roderic Campbell
Roderic Campbell

Reputation: 719

NSLog is stating that you've got an array with a single element, which contains an array of 5 locations. Try: objects.firstObject.count

Upvotes: 2

Related Questions