Search code examples
parse-platformxcode6messagepfobject

Parse error when trying to upload PFObject


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.


Solution

  • 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")
            }
        }
    }