【问题标题】:Swift cannot invoke append with an argument of type (name: String, String) [duplicate]Swift 不能调用带有类型参数的附加(名称:字符串,字符串)[重复]
【发布时间】:2016-04-18 21:48:37
【问题描述】:

我得到了错误

Swift 不能调用带有类型参数的附加(名称:字符串,字符串)

我在这里附上了我的部分代码。

func gotData(result:NSDictionary){

    if result.count == 0{
        print("data is nil")
    }else{

        if result["Search"] == nil{
            print("no results found")
            Global.showAlert("No Movie Found", message: "Double check the name", view: self)
        }else{
            var results = result["Search"] as! [NSDictionary]

            for result in results as [NSDictionary]{
                var name = result["Title"] as! String
                var year = result["Year"] as! String
                var imdbID = result["imdbID"] as! String

                self.movieList.append(name:"\(name), (\(year))", imdbID:"\(imdbID)")
            }
            tableView.reloadData()



        }
    }
}

错误发生在这一行

self.movieList.append(name:"\(name), (\(year))", imdbID:"\(imdbID)")

有人对如何解决这个问题有任何想法吗?

【问题讨论】:

  • 大概是这样的吧? stackoverflow.com/questions/32654654/…(只是猜测)
  • self.movi​​eList的元素类型是什么?
  • @EricD。似乎工作。我不知道究竟是为什么,但确实如此。那很好。谢谢。
  • 因为 self.movi​​eList 中的元素类型是元组
  • 不客气。建议:接受“投票关闭为重复”。这样未来的读者会发现这两个问题是相似的,这可以帮助他们。

标签: string swift list append


【解决方案1】:

像这样编辑行

self.movieList.append((name:"\(name), (\(year))", imdbID:"\(imdbID)"))

让它工作。谢谢@EricD

【讨论】:

    猜你喜欢
    • 2021-10-21
    • 2021-10-13
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多