2015-06-03 30 views
0

我是相當新的雨燕和分析,但這裏是我的問題: 我下載了一個簡單的斯威夫特/解析的應用程序,它改編和它工作得很好,直到我決定更新現有的Parse SDK。 我得到錯誤的錯誤,我不能得到它的工作。斯威夫特 - 更新解析SDK 1.7.4後 - 錯誤信息

我不能夠分配什麼了currentuser:

即:

currentuser["location"] = PFGeoPoint(location: location) 
currentuser["interestedCategory"] = self.pickerChoice 
currentuser["locationLimit"] = Int(locationSlider.value) 

我收到滾動誤差(也可用於詮釋等)

SettingViewController.swift:157:50: Cannot assign a value of type 'NSString!' to a value of type 'AnyObject?

'

甚至

self.pickerChoiceRow = currentuser.objectForKey("interestedCategoryRow") as! Int 

我獲得以下錯誤信息:

SettingViewController.swift:82:36: Value of optional type 'PFUser?' not unwrapped; did you mean to use '!' or '?'?

而且這是不工作了:

if currentuser["job1_objectId"] != nil { 

...... 

} 

因爲我收到以下錯誤:

OverviewInsertViewController.swift:185:12: Binary operator '!=' cannot be applied to operands of type 'AnyObject?' and 'nil'

,這也是造成問題!

var 1_objectId:NSString! = "" 

self.1_objectId = currentuser["job1_objectId"] as! NSString 
        var query_jobs = PFQuery(className: "Jobs") 
        query_jobs.getObjectInBackgroundWithId(self.1_objectId as String) { 
         (object: PFObject!, error: NSError!) -> Void in 
         if (error == nil) { 

對於那些我收到以下錯誤行:

OverviewInsertViewController.swift:144:77: Cannot assign a value of type 'NSString' to a value of type 'NSString!'

OverviewInsertViewController.swift:146:32: Cannot invoke 'getObjectInBackgroundWithId' with an argument list of type '(String, (PFObject!, NSError!) -> Void)'

請幫助我,一切運行良好與老解析SDK?

回答

0

對於第一點,試圖更新對象的值時,例如,位置,我用下面的代碼:

var query:PFQuery = PFQuery(className:"Location") 
    query.whereKey("user", equalTo: PFUser.currentUser()!) 
    //query Parse 
    query.getFirstObjectInBackgroundWithBlock { 
     (object: PFObject?, error: NSError?) -> Void in 
     if error != nil || object == nil { 
      println("The getFirstObject request failed.") 
     } else if let object = object{ 
      // The find succeeded. 
      println("Successfully retrieved the object.") 

      object["location"] = point 
      object.saveInBackground() 
     } 

    } 

請注意「否則,如果讓對象=對象」,補充說,條件幫助我與你提到的第一個錯誤。

希望它服務。