这是我正在尝试的,基本上只为当前用户查询“事件”类的关键“类别”:
class AllEntriesTableViewController: UITableViewController {
var allEntries = [""]
override func viewDidLoad() {
super.viewDidLoad()
var user = PFUser.currentUser()
var query = PFQuery(className:"event")
query.whereKey("user", equalTo: user)
query.includeKey("category")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
self.allEntries.removeAll(keepCapacity: true)
// Do something with the found objects
for object in objects {
var allEnt:String = object as String
self.allEntries.append(allEnt.category)
}
} else {
// Log details of the failure
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
答案 0 :(得分:0)
您好像期待allEnt
成为String
而不是event
。
var allEnt:String = object as String
self.allEntries.append(allEnt.category)
如果您打算在allEnt
上访问event
作为属性,则应该将allEnt.category
设为event
vars。也许你忘记了某种查找?类似的东西:
convertToEvent(allEnt)
self.keyToEventDictionary[allEnt]
或者,您的objects
列表实际上可能是category
结果的列表,您应该这样做:
self.allEntries.append(allEnt)