我有一個Parse.com中的對象數組,我嘗試迭代並取出objectId。我的方法如下:通過循環將NSMutableDictionary添加到數組導致覆蓋以前的值
-(void)buildActivityDictionary{
arrayOfArrays = [[NSMutableArray alloc] init];
arrayForDicts = [[NSMutableArray alloc] init];
activityDict = [[NSMutableDictionary alloc] init];
for (PFObject *object in someArray){
PFObject *fromUser = [object objectForKey:@"fromUser"];
PFObject *toUser = [object objectForKey:@"toUser"];
NSString *requestId = object.objectId;
NSString *fromUserId = fromUser.objectId;
NSString *toUserId = toUser.objectId;
[activityDict setObject:requestId forKey:@"requestId"];
[activityDict setObject:fromUserId forKey:@"fromUserId"];
[activityDict setObject:toUserId forKey:@"toUserId"];
[arrayForDicts addObject:activityDict];
[arrayOfArrays addObject:arrayForDicts];
}
NSLog(@"\narrayFofArrays = %@", arrayOfArrays);
}
我該如何達到理想的效果?我試過用setValue
來代替,但沒有骰子。此外,當我嘗試將每個陣列添加到一個新陣列[arrayOfarrays addObject:arrayForDicts]
時,我得到相同的結果。這是我的日誌輸出。任何建議將不勝感激。
arrayForDicts = (
{
fromUserId = lVlLN0ucKQ;
requestId = SSrFp9pV1Y;
toUserId = SG359LXCtA;
},
{
fromUserId = lVlLN0ucKQ;
requestId = SSrFp9pV1Y;
toUserId = SG359LXCtA;
},
{
fromUserId = lVlLN0ucKQ;
requestId = SSrFp9pV1Y;
toUserId = SG359LXCtA;
},
{
fromUserId = lVlLN0ucKQ;
requestId = SSrFp9pV1Y;
toUserId = SG359LXCtA;
}
)
編輯:
someArray = (
"<Activity:PMZO9LJ3os:(null)> {\n ACL = \"<PFACL: 0x1579c520>\";\n activityType = request;\n fromUser = \"<PFUser:rJWrNWO15W>\";\n toUser = \"<PFUser:SG359LXCtA>\";\n}",
"<Activity:aV3zz4iVrE:(null)> {\n ACL = \"<PFACL: 0x157e6960>\";\n activityType = request;\n fromUser = \"<PFUser:SG359LXCtA>\";\n toUser = \"<PFUser:SG359LXCtA>\";\n}",
"<Activity:K7504CAYnl:(null)> {\n ACL = \"<PFACL: 0x157e7810>\";\n activityType = request;\n fromUser = \"<PFUser:xMbXLMIv99>\";\n toUser = \"<PFUser:SG359LXCtA>\";\n}",
"<Activity:SSrFp9pV1Y:(null)> {\n ACL = \"<PFACL: 0x157e72c0>\";\n activityType = request;\n fromUser = \"<PFUser:lVlLN0ucKQ>\";\n toUser = \"<PFUser:SG359LXCtA>\";\n}"
)
NSLog someArray.What的輸出是什麼? – 2014-10-01 16:06:01
嘿Nimisha。我已更新我的原始問題以顯示日誌。 – 2014-10-01 20:19:56