Array of tuples in Swift

前端 未结 3 439
小鲜肉
小鲜肉 2020-11-30 12:32

I have a function:

func parseJSON3(inputData: NSData) -> NSArray {
    var tempDict: (id:Int, ccomments:Int, post_date:String, post_title:String, url:Stri         


        
3条回答
  •  鱼传尺愫
    2020-11-30 13:08

    It looks to me like resultArray.append() is treating the tuple a little bit like a variadic parameter, and trying to expand the tuple to match its own arguments. It's complaining about your second parameter because it's only expecting one. I haven't seen this behavior for Array.append() documented anywhere, so I would say it's a bug in Swift.

    Using the appending operator += doesn't seem to have that issue:

    resultArray += tempDict
    

提交回复
热议问题