Parse error when trying to upload PFObject

107 Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

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")
        }
    }
}
0
On

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.