问题描述
我做了一些研究,仍然不知道是什么是我的代码导致这个错误(我知道是什么原因,但我不知道为什么...)
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...)
基本上,我从Parse Cloud Code中检索数组 results
。然后我将其发送到ViewController2,以 UILabel
的格式打印出数组的一部分。当我这样做我得到编译器错误。这真的让我很困惑!
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!
请注意, result
,我检索的数组包含字符串和布尔值这就是为什么我让它 AnyObject
,所以我以后可以投入特定的部分。
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代码:
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代码(其中一部分):
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代码:
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.
}
推荐答案
尝试更改:
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
当使用带有findObjectsInBackgroundWithBlock的AnyObject时,我也有同样的错误。类似于:,这是由于更改Parse SDK
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
这篇关于“命令由于信号而失败:分段故障:11” - 什么是问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!