Anyone know how I can show a UIProgressView while I save synchronous to parse.com?
I try to show a progress view before I start the sync save and hide it after the save is done, but this doesn't work. It doesn't show the progress view and just start save right away.
I am starting to think that the sync save takes all the power from everything else and a async save is the best for this issue. But in my case I have to save synchronous since I show the saved data directly after it is saved.
Anyone know how this can be done?
self.startProgress()
self.saveSynchronousToParse()
self.stopProgress()
A 'synchronous' method is also known as a 'blocking' method - it effectively blocks the current thread until it completes.
By default your app is running in the main queue, and this is the queue that performs all of the UI tasks, so once you call "saveSynchronousToParse" (which presumably calls save
or some similar synchronous Parse function) your UI will freeze until the task completes. You will probably receive a warning in the console that you are executing a synchronous task on the main thread.
A progress view doesn't really make sense in this case, because you don't get any feedback from the Parse API as to how much progress has been made in saving the information.
A UIActivityView
makes more sense. You can use the following to achieve what you are after using an UIActivityView
self.activityView.startAnimating()
self.somePFObject.saveInBackgroundWithBlock {
(success: Bool!, error: NSError!) -> Void in
dispatch_async(dispatch_get_main_queue(),{
self.activityView.stopAnimating()
});
if success {
println("success")
} else {
println("\(error)")
}
}