我有一个功能:
func parseJSON3(inputData: NSData) -> NSArray { var tempDict: (id:Int, ccomments:Int, post_date:String, post_title:String, url:String) = (id: 0, ccomments: 0, post_date: "null", post_title: "null", url: "null") var resultArray: (id:Int, ccomments:Int, post_date:String, post_title:String, url:String)[] = [] var error: NSError? var jsonDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary var firstArray = jsonDictionary.objectForKey("locations") as NSArray for dict in firstArray { tempDict.id = dict.valueForKey("ID") as Int tempDict.ccomments = dict.valueForKey("ccomments") as Int tempDict.post_date = dict.valueForKey("post_date") as String tempDict.post_title = dict.valueForKey("post_title") as String tempDict.url = dict.valueForKey("url") as String resultArray.append(tempDict) } return resultArray }
排队
resultArray.append(tempDict)
我有一个错误:
调用中缺少参数“ ccomments”的参数
为什么?请帮助....
在我看来,就像resultArray.append()对待元组有点像可变参数,并试图扩展元组以匹配其自身的参数。它抱怨您的第二个参数,因为它只期待一个。我没有在Array.append()任何地方看到这种行为的记录,因此我想说这是Swift中的错误。
resultArray.append()
Array.append()
使用追加运算符+=似乎没有这个问题:
+=
resultArray += tempDict