2

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()
TommyF
  • 381
  • 1
  • 7
  • 22

1 Answers1

3

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)")
    }
}
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • This is good stuff Paulw11. With this kind of save I actually don't need the activityView. Earlier I saved with SaveEventually() which as it states saves eventually. That did not do if for me since I show the saved data in the next segue and it wasn't saved once the segue kicked in. Then I used Save() which is synchronous and took all the time in the world. Your example on the other hand saves actually so fast that there is no need for the activityView. Thanks, man! – TommyF Mar 08 '15 at 19:29