当NSPredicate
或objectIds
是我的fb ID时,我使用senderID
进行解析查询以获取所有receiverID
:
let setPredicate = NSPredicate(format: "senderID = %@ OR receiverID = %@", fbID, fbID)
var query = PFQuery(className: "Groups", predicate: setPredicate)
query.addDescendingOrder("updatedAt")
我然后将结果添加到NSMutableDictionary
,然后添加到NSMutableArray
,如下所示:
query.findObjectsInBackgroundWithBlock
{(objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil
{
if let objects = objects as? [PFObject]
{
for object in objects
{
if setPredicate = NSPredicate(format: "senderID", fbID)
self.groupDetailsDict.setValue(object.objectForKey("objectId") as! String, forKey: "groupID")
self.groupDetailsDict.setValue(object.objectForKey("senderName"), forKey: "senderName")
self.groupDetailsDict.setValue(object.objectForKey("receiverName"), forKey: "receiverName")
self.groupDetails.addObject(self.groupDetailsDict)
}
}
else
{
println("Error: \(error) \(error!.userInfo)")
}
}
else
{
println(error?.description)
}
}
如果我的receiverName
与fbID
匹配,我只想添加senderId
,如果senderName
与fbID
匹配,我只想添加receiverName
。
我可以在里面使用if else语句吗?如果是,那怎么样?
答案 0 :(得分:0)
在第一种情况下,不太了解你的逻辑比较ID和ID,第二种情况下ID是ID,但如果我们假设test
是我们的目标数组(对不起,请不要非常明白groupDetailsDict
的意思,也许你可以解释一下)代码看起来像(有了所有适当的快速解开):
if let senderId = object["senderId"] as? String, receiverName = object["receiverName"] as? String where senderId == fbID {
test.append(receiverName)
} else if let receiverName = object["receiverName"] as? String, senderName = object["senderName"] as? String where receiverName == fbID {
test.append(senderName)
}