Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot assign a value of type 'AnyObject?' to a value of type 'String!' - Swift with Parse

Tags:

string

swift

After updating my code to swift 1.2 i stuck on one point

var Question:String!
var Answere:String!
var Answeres:[String]!
var ObjectIDsArray:[String]!
var ButtonNumber:String!
var ObjectIDsArrayCount:Int!


var query : PFQuery = PFQuery(className: "AddonQuiz")
        query.getObjectInBackgroundWithId(QuestionID){
            (ObjectHolder : PFObject?, error : NSError?) -> Void in

            if error == nil {

                self.Question = ObjectHolder["ImageLink"] as! String
                self.Answeres = ObjectHolder["Answeres"] as! Array
                self.Answere = ObjectHolder["Right"] as! String




                if self.Answeres.count > 0 {

With the errors

Cannot assign a value of type 'AnyObject?' to a value of type 'String!'
Cannot assign a value of type 'AnyObject?' to a value of type '[String]!'
Cannot assign a value of type 'AnyObject?' to a value of type 'String!'

for Lines

self.Question = ObjectHolder["ImageLink"] as! String
self.Answeres = ObjectHolder["Answeres"] as! Array
self.Answere = ObjectHolder["Right"] as! String

Any work around for that?

like image 843
Fabian Boulegue Avatar asked Apr 11 '15 13:04

Fabian Boulegue


1 Answers

if let ObjectHolder = ObjectHolder { 
    self.Question = ObjectHolder["ImageLink"] as! String
    self.Answeres = ObjectHolder["Answeres"] as! Array
    self.Answere = ObjectHolder["Right"] as! String
}
like image 109
Leo Dabus Avatar answered Nov 15 '22 13:11

Leo Dabus