I am loading objects from the server async, I think, but the app stops and wait for the load to finish. I tried to use GDC, but that just doesn’t load the objects at all.
The function is called in the viewDidLoad.
func findWeeksAsync() {
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
debugPrint("Loading weeks")
MMProgressHUD.showWithTitle("Loading")
self.weekCollection.removeAll()
let dataQuery = BackendlessDataQuery()
let currentUser = backendless.userService.currentUser
let whereClause = "ownerId = '\(currentUser.objectId!)'"
dataQuery.whereClause = whereClause
dataQuery.queryOptions.sortBy = ["startDate DESC"]
var error: Fault?
let weeks = backendless.data.of(FDWeek.ofClass()).find(dataQuery, fault: &error)
if error == nil {
for obj in weeks.data {
let week = obj as! FDWeek
self.weekCollection.append(week)
}
debugPrint("Found \(weekCollection.count) weeks")
MMProgressHUD.dismiss()
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
self.tableView.reloadData()
} else {
debugPrint("Server reported an error: \(error)")
MMProgressHUD.dismissWithError("Please try later", title: "Server Error!", afterDelay: 4)
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
}