"The command failed due to a signal: Segmentation Error: 11" - What is the problem?

I did some research and still don't know what causes this error in my code (well, I know what causes it, but I don't know why ...)

Essentially, I am extracting an array resultsfrom the parsing cloud code. Then I send it to ViewController2 to print the section of the array in format UILabel. When I do this, I get a compiler error. It really bothers me!

Please note that the resultarray I am extracting contains both strings and booleans, so I made it AnyObjectto add specific parts later.

Cloud Code:

Parse.Cloud.define("checkAccountStatus", function(request, response) {

var results = [];
var query = new Parse.Query(Parse.User);
query.equalTo("username", request.params.username);
query.first({
        success: function(getUserData) {

        if (request.params.operation == 1) {

            var passwordChanged = getUserData.get("passwordChanged");
            var question1 = getUserData.get("question1");
            var question2 = getUserData.get("question2");
            var question3 = getUserData.get("question3");

            results.push(passwordChanged);
            results.push(question1);
            results.push(question2);
            results.push(question3);

        }

        else {

            if (request.params.answerToQuestion1 == getUserData.get("answer1")) {

                results.push(true)
            }

            else {

                results.push(false)
            }

            if (request.params.answerToQuestion2 == getUserData.get("answer2")) {

                results.push(true)
            }

            else {

                results.push(false)
            }

            if (request.params.answerToQuestion3 == getUserData.get("answer3")) {

                results.push(true)
            }

            else {

                results.push(false)
            }
        }

            response.success(results);

        },
        error: function(error) {

            response.error("There was an error");

        }
});
});

ViewController1 code (part of it):

 var data: AnyObject!

 PFCloud.callFunctionInBackground("checkAccountStatus", withParameters: ["username" : self.username.text, "operation" : 1]) {
            (result: AnyObject!, error: NSError!) -> Void in

            if (error == nil) {

            self.data = result

            //...

            }
 }

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "reset") {
        var svc = segue.destinationViewController as ViewController2;

        svc.data = data
    }
}

ViewController2 Code:

@IBOutlet var question1: UILabel!
var data: AnyObject!

override func viewDidLoad() {
     super.viewDidLoad()

     question1.text = data[1] as String! //THIS GIVES ME THE ERROR.
}
0
1

:

PFCloud.callFunctionInBackground("checkAccountStatus", withParameters: ["username" : self.username.text, "operation" : 1]) {
        (result: AnyObject!, error: NSError!) -> Void in

PFCloud.callFunctionInBackground("checkAccountStatus", withParameters: ["username" : self.username.text, "operation" : 1]) {
        (result: PFObject!, error: NSError!) -> Void in

AnyObject findObjectsInBackgroundWithBlock. : , Parse SDK

+2

All Articles