由於升級到Xcode7,我收到以下錯誤:斯威夫特 - 無法調用初始化類型「的NSDictionary」
Cannot invoke initializer for type 'NSDictionary' with an argument list of type '(objects: [AnyObject!], forKeys: [String])'
在這行代碼:
self.sessionBids!.addObject(NSDictionary(objects: [PFUser.currentUser().objectId, PFUser.currentUser().objectForKey("username"), self.bidTextField.text], forKeys: ["user", "name", "bid"]))
有人能解釋爲什麼嗎?
編輯:這裏是代碼的完整塊
if(self.bidTextField.text!.rangeOfString("^[0-9]*$", options: .RegularExpressionSearch) != nil) {
self.sessionBids = array[0].objectForKey("bids") as? NSMutableArray
var lastSessionBid : NSDictionary
SVProgressHUD.showProgress(50)
var previousHighBid : Int! = 0
if(self.sessionBids == nil) {
self.sessionBids = NSMutableArray()
} else {
lastSessionBid = self.sessionBids.objectAtIndex(self.sessionBids.count - 1) as! NSDictionary
previousHighBid = Int(lastSessionBid.objectForKey("bid") as! String)
}
if(previousHighBid >= Int(self.bidTextField.text!)) {
print("bid is lower than current bid")
SVProgressHUD.showErrorWithStatus("Bid is lower than current bid!")
return
} else {
self.sessionBids!.addObject(NSDictionary(objects: [PFUser.currentUser().objectId, PFUser.currentUser().objectForKey("username"), self.bidTextField.text], forKeys: ["user", "name", "bid"]))
SVProgressHUD.showProgress(75)
self.session.setObject(self.sessionBids, forKey: "bids")
self.session.save()
self.keyboardShowing = false
self.reloadSessionBids()
SVProgressHUD.showProgress(100)
SVProgressHUD.showSuccessWithStatus("Successfully Added Bid")
}
} else {
SVProgressHUD.showErrorWithStatus("Bid must be a number!")
}
請顯示一些關於'PFUser'。 –