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.
}