2013-03-25 67 views
0

[。這可能是一個noob問題,但我花了很多時間來解決這個問題]的Xcode /解析 - PFQuery NSMutableArray的問題

基本上,我使用www.parse.com服務來存儲我雲中的數據。我檢索NSArray中調用的對象,其結果是在控制檯:

2013-03-25 19:59:06.118 app[18960:c07] (
"<users:u8WRDUlfVg:(null)> {\n pairs =  (\n  14120151,\n  14749606,\n  17230018\n );\n username = GeoffroyMorel;\n}" 
) 

然後,因爲我希望「對」值一個NSMutableArray,我這樣做:

pairsUserMutableArray = [objects mutableArrayValueForKey:@"pairs"]; 

在控制檯的結果是相當不錯的,除了附加的一對圓括號(這可能是以下問題的原因):

2013-03-25 19:59:06.119 app[18960:c07] (
    (
    14120151, 
    14749606, 
    17230018 
) 
) 

現在的問題,當我試圖添加一個對象,並顯示在缺點的結果OLE它會用括號這樣的:

2013-03-25 20:02:45.887 app[18960:c07] (
    (
      (
     14120151, 
     14749606, 
     17230018 
    ), 
    15749606 
) 
) 

我希望它是這樣的:

2013-03-25 20:02:45.887 app[18960:c07] (
    14120151, 
    14749606, 
    17230018, 
    15749606 
) 

感謝您的幫助,我敢肯定,我只是缺少一個線,可以正確排序我的NSMutableArray 。

回答

0

好的,我剛剛找到了答案,我沒有注意到從查詢接收到的「對象」是一個NSArray!所有你需要的是:

PFQuery *query = [PFQuery queryWithClassName:@"Users"]; 
[query whereKey:@"username" equalTo:userAccount.username]; 

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
if (!error) { 
    NSLog(@"%@", objects); 

    NSArray *array = [objects objectAtIndex:0];//Selects the first "object" from all the "objects" 
    array = [array valueForKey:@"pairs"];//Makes a NSArray from the "pairs" values 
    pairs = [array mutableCopy];//Converts the array to a NSMutableArray 

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