Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了nsarray – Swift中的元组数组大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有一个功能: 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
我有一个功能
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,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的一个错误.

使用追加的operator =似乎没有这个问题:

resultArray += tempDict

大佬总结

以上是大佬教程为你收集整理的nsarray – Swift中的元组数组全部内容,希望文章能够帮你解决nsarray – Swift中的元组数组所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。