I'm completely lost with swift. I am trying to split an array of objects (retrieved using the Parse SDK) based on a common key. Basically I would like to make a COUNT + GROUP BY, but I could not find a way to make a GROUP BY with the Parse SDK, so I am trying to group the objects and count them by the code. But first, what I am writing looks horrible, and secondly that does not even compile and I can't understand why.
This is the code I'm using
var groupedEntries = [String: [String: AnyObject?]]()
...
let query = PFQuery(className: "Entry")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
var groupingKey: String
for object in objects {
groupingKey = object[groupingKey] as String
if self.groupedEntries[groupingKey] != nil {
self.groupedEntries[groupingKey]["count"] = self.groupedEntries[groupingKey]["count"] + 1
} else {
self.groupedEntries[groupingKey]["count"] = 1
}
}
self.tableView.reloadData()
}
}
And the compiler gives the following error : 'String' is not convertible to 'DictionaryIndex'. Whatever I try I get an error related to optionals or wrapping.
Thanks to anybody that will help me :)