PFObject到NSArray不起作用

时间:2015-02-18 17:09:52

标签: ios objective-c arrays parse-platform nsarray

我在Parse中有一个坐标数组,我需要将其转换为多个坐标值的NSArray。但是,当我从Parse中拉出数组时,它就好像整个数组中只有一个对象,而显然更多。我无法弄清楚如何在任何地方解决这个问题。

这是我的代码:

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]);
    }
}];

以下是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

正如您所看到的,此数组中显然有五个对象,但Parse将其视为单个对象。发生了什么事?

1 个答案:

答案 0 :(得分:2)

NSLog声明您已经拥有一个包含单个元素的数组,其中包含一个包含5个位置的数组。尝试:objects.firstObject.count