“Command failed due to signal: Segmentation fault: 11” - What is the issue?

跟風遠走 提交于 2020-01-07 05:05:15

问题


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

Essentially, I retrieve an array, results, from Parse Cloud Code. Then I send it to ViewController2 to print out a section of the array in the format of a UILabel. When I do this I get the compiler error. This is really confusing me!

Please note that result, the array that I retrieve contains both Strings and Boolean values which is why I made it AnyObject so I could cast 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.
}

回答1:


Try changing:

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

to

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

I had the same error when using AnyObject with findObjectsInBackgroundWithBlock. Seems similar to: this link which was caused due to changes in the Parse SDK



来源:https://stackoverflow.com/questions/28647925/command-failed-due-to-signal-segmentation-fault-11-what-is-the-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!