1

I'm trying to make a messaging app in Parse, but I get this error when trying to upload a PFObject.

The error says:

2014-11-22 14:43:21.154 Parse demo[688:27950] Warning: A long-running operation is being executed on the main thread. Break on warnBlockingOperationOnMainThread() to debug.

and my code is for the sender-button is:

@IBAction func sendButton(sender: AnyObject) {
    var message = PFObject(className:"message")
    message["message"] = send.text
    message.save()

where send.text is just a text-box.

Any recommendations or ways to proceed would be highly appreciated.

martin
  • 1,894
  • 4
  • 37
  • 69

2 Answers2

2

Try this instead. then you save in a background blok

@IBAction func sendButton(sender: AnyObject) {
    var message = PFObject(className:"message")
    message["message"] = send.text
    message.saveInBackgroundWithBlock {
        (succeeded: Bool!, error: NSError!) -> Void in
        if (error != nil) {
            println("Save : \(error)")
        }
        else{
                println("Success! with save")
        }
    }
}
Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
KennyVB
  • 745
  • 2
  • 9
  • 28
  • Thank you very much, it worked perfectly. What is weird is that even though this error came up every time before, I can now see that all my other attempts has also been uploaded to Parse, do you know why? – martin Nov 22 '14 at 14:58
0

This is not exactly an error, but more a hint, that it'll block the app because you are making a synchronous save call. Use one of the saveInBackground* methods instead and the save will take place asynchronously on a background job.

SAE
  • 1,609
  • 2
  • 18
  • 22