I am a bit confuse about async
i thought async was to be running the block while i can continue to do other stuff but it seems like for loop have not finish it goes to another lines of code it makes it crashes since the object retreiving should not be nil if for loop have finish running .
Here my Code
backendless.persistenceService.of(Activity.ofClass()).find(
query,
response: { ( users : BackendlessCollection!) -> () in
let currentPage = users.getCurrentPage()
for followU in currentPage as! [BackendlessUser] {
print(followU)
user = followU
}
let activity = Activity()
activity.fromUser = backendless.userService.currentUser
activity.toUser = user as! BackendlessUser //Crashes Here Since FollowU still retrieving data /nil
activity.type = "follow"
let activityStore = backendless.data.of(Activity.ofClass())
activityStore.save(
activity,
response: { (result: AnyObject!) -> Void in
print("Follow Have Been Successfully Uploaded(Activity Class) --- StatusUpload (UIViewController)")
},
error: { (fault: Fault!) -> Void in
print("fServer reported an error: \(fault)")
}) // save object asynchronously
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)