'Extra arguments at positions in call' 是什么意思?

What does 'Extra arguments at positions in call' mean?

我有一个字符串 - “productRaw”,我将其拆分以显示在单独的 sectionData 单元格中,同时在相同的“项目 1”cellData table 视图下。这是我用来拆分字符串并将每个单独的部分添加到单独的 sectionData 单元格中的代码。

let group_array = document["product"] as? [String] ?? [""]
                                 
let productName1 = group_array.first ?? "No data to display :("
                                 
let productRaw = "\(productName1)"

let componentsRaw = productRaw.components(separatedBy: ", ")
                                 
var product = [String: String]()

for component in componentsRaw {
      
       let keyVal = component.components(separatedBy: ": ")

       product[keyVal[0]] = keyVal[1]
                                 
       }
                                 
       if let productName = product["Product Name"], let listingPrice = product["Listing Price"], let briefDescription = product["A brief description"], let productURL = product["Product URL"], let activeUntil = product["Listing active until"] { 
                                 
       self.tableViewData = [cellData(opened: false, title: "Item 1", sectionData: [productName],  [listingPrice], [briefDescription], [productURL], [activeUntil])]
 }

当我在我的 sectionData 中仅使用 [productName] 时,我要在第一部分 - “项目 1” 中声明要显示的单个单元格,然后编译没有任何问题。但是,当我也将 , [listingPrice], [briefDescription], [productURL], [activeUntil] 添加到我的 sectionData 时,我收到 [cellData(opened: 语法的以下错误。

Extra arguments at positions #4, #5, #6, #7 in call

所以我的问题是,为什么我会收到上述错误,我该如何解决?

如果不看 cellData 的声明,很难知道哪里出了问题,但据我所知,最明显的原因是 cellData 的构造函数只接受 3 个参数共 7 个

this answer 中,他们还提到,如果您没有为每个参数传递正确的类型,则可能会抛出此错误。

如果给出 cellData

的定义,我们可以提供更多帮助

when I only use [productName] in my sectionData then this compiles

[productName] 是一个包含一项的数组。

I also add , [listingPrice], [briefDescription], [productURL], [activeUntil] to my sectionData

您正在添加额外的数组,以逗号分隔,编译器将其解释为额外的函数参数。

self.tableViewData = [cellData(opened: false, title: "Item 1", sectionData: [productName, listingPrice, briefDescription, productURL, activeUntil])]

将所有项目放在一组方括号内。这就是您声明具有多个项目的数组的方式。