【发布时间】:2016-05-28 14:00:16
【问题描述】:
调用中的额外参数“错误”
func handleReceivedDataWithNotification(notification:NSNotification){
let userInfo = notification.userInfo! as Dictionary
let receivedData:NSData = userInfo["data"] as! NSData
let message = NSJSONSerialization.JSONObjectWithData(receivedData, options: NSJSONReadingOptions.AllowFragments, error: nil) // This the error line
let senderPeerId:MCPeerID = userInfo["peerID"] as! MCPeerID
let senderDisplayName = senderPeerId.displayName
if message.objectForKey("string")?.isEqualToString("New Game") == true{
let alert = UIAlertController(title: "TicTacToe", message: "\(senderDisplayName) has started a new Game", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
resetField()
}else{
var field:Int? = message.objectForKey("field")?.integerValue
var player:String? = message.objectForKey("player") as? String
if field != nil && player != nil{
fields[field!].player = player
fields[field!].Player(player!)
if player == "x"{
currentPlayer = "o"
}else{
currentPlayer = "x"
}
checkResults()
}
}
}
【问题讨论】:
-
对于投票结束问题的人来说,不,很清楚要问什么。
-
Swift 改为使用
throws,而不是输入输出错误。见developer.apple.com/library/ios/documentation/Swift/Conceptual/… -
有很多关于“调用中的额外参数'错误'”的问题(例如在相关列表中)。搜索“JSONObjectWithData Extra argument 'error' in call”会立即显示解决方案。