根据数组

时间:2015-11-13 14:53:07

标签: arrays swift parse-platform pfquery pfobject

我看了一遍,人们说使用whereKey: equalTo:将在数组中工作但由于某种原因它不适合我。我正在尝试让用户搜索标签,并显示包含该标签的所有帖子。当我删除whereKey: equalTo:时,我得到了所有结果但是没有得到任何结果。任何帮助将不胜感激。以下是负责创建和查询类的代码。

import Foundation

class WallPost: PFObject, PFSubclassing {

@NSManaged var post: String
@NSManaged var user: PFUser
@NSManaged var tags: [String]

init(post: String, user: PFUser, tags: [String]) {
    super.init()

    self.post = post
    self.user = user
    self.tags = tags
}

override init() {
    super.init()
}



override class func query() -> PFQuery?{
    let query = PFQuery(className: parseClassName())
    query.includeKey("user")
    query.whereKey("tags", equalTo: "rock")




    query.orderByDescending("createdAt")
    return query
}

class func parseClassName() -> String {
    return "POST"
}

override class func initialize(){
    var onceToken: dispatch_once_t = 0
    dispatch_once(&onceToken) {
        self.registerSubclass()
    }
}
}

I've added a screenshot of the parse class here

1 个答案:

答案 0 :(得分:0)

如果"标签"是解析中的数组的名称,然后您需要将此参数添加到您的查询:

query.whereKey("rock", containedIn: "tags")