无法指定类型'任何对象的值?'类型为' String!' - 与Parse Swift

时间:2015-04-11 13:42:53

标签: string swift

将我的代码更新为swift 1.2后,我坚持了一点

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 {

有错误

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

有什么解决方法吗?

1 个答案:

答案 0 :(得分:13)

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