将我的代码更新为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
有什么解决方法吗?
答案 0 :(得分:13)
if let ObjectHolder = ObjectHolder {
self.Question = ObjectHolder["ImageLink"] as! String
self.Answeres = ObjectHolder["Answeres"] as! Array
self.Answere = ObjectHolder["Right"] as! String
}