I'm new to Swift and I'm learning how to use parse.com to store data an retrive it. I'm downloading an array of PFObjects from PARSE and then I need to turn it into a structure, so I created this function:
func queryDownload (user : PFUser) {
let objects: [PFObject]
let query = PFQuery(className: "Gluc")
query.whereKey("user", equalTo: user)
do {
objects = try query.findObjects() as [PFObject]
} catch {
print("ERROR")
}
let returnedObjects = objects {
let elements = self.returnedObjects.count
for i in 0...elements-1 {
self.dataArray.append(MyData(gluc: Int(self.returnedObjects[i]["meassure"] as! String)!, fec: self.returnedObjects[i]["fec"] as! Date, alimento: self.returnedObjects[i]["alim"] as! Int, comentarios: self.returnedObjects[i]["notes"] as! String))
}
}
self.dataArrayOrdered = self.dataArray.sorted(by: { $0.fec.compare($1.fec) == .orderedAscending})
print(self.dataArrayOrdered)
}
But I can't run it because in this line:
let returnedObjects = objects {
It sais "Cannot call value of non-function type [PFObject]"
I'm not sure how to avoid this problem, so any help would be appreciated
Thanks
is a syntax error, you probably wanted to optional bind the value
but
objectsis non-optional and optional binding is not possible.Just assign the value to the variable and remove the braces
It's very important to put all good code in the
doblock and print the actual error rather than the simple literal string"ERROR"However this is Swift and there is a smarter and more convenient way using the
mapfunction