gpt4 book ai didi

arrays - swift 2 : Extra argument in call for array and struct

转载 作者:行者123 更新时间:2023-11-30 10:10:19 25 4
gpt4 key购买 nike

我在单独的类中创建了一个数组并初始化。当我进行 init(index: Int) 尝试获取值时,“调用中的额外参数(条目)”出现,如代码中所示。我还是一个新学习者。在寻找线索后,我无法得到有意义的解决方案。我真的很感谢你的指导。

import Foundation

var wordlists = [
WordList(
placeCue: "Audio0",
suggestionList: ["WaterBottle.pdf", "Medicine.pdf", "Dentist.pdf", "SomethingElse.pdf"], // Extra argument in this list.
audio: ["Audio16", "Audio17", "Audio14", "Audio21"] // Extra argument in this list.
)
]
<小时/>
import Foundation
import UIKit

struct WordList {

var placeCue: String?
var suggestionList: [UIImage] = [UIImage]()
var audio: [String] = [String]()


init(index: Int){
self.wordlists = wordlists
let wordlistEntry = wordlists[index]()
wordlistEntry = [suggestionList]();[audio]

let iconName = wordlistEntry.suggestionList[] as! String!
suggestionList += UIImage(named: iconName)

placeCue = wordlistEntry[placeCue] as! String!
audio = wordlistEntry[audio] as! String!


}

}
<小时/>

所以我接受了建议,几乎就完成了......,但我遇到了另一个问题。现在,它在 suggestList = UIImage!(named: iconName) 行显示“参数标签 '(named:)' 与任何可用的重载都不匹配”。并且数组坚持不能将 String 转换为 UIImage。我非常感谢你的建议。谢谢!

extension WordList {
init(index: Int){
let wordlistLibrary = wordlists
let wordlistEntry = wordlistLibrary[index]

let iconName = wordlistEntry[suggestionList] as! String!

suggestionList = UIImage!(named: iconName) // problem here.

suggestionList += wordlistEntry[suggestionList] as! [UIImage]
placeCue = wordlistEntry[placeCue!] as! String!
audio += wordlistEntry[audio] as! [String]
}
}

最佳答案

只有在没有任何自定义初始化程序(您的情况下有)时,编译器才会自动为所有属性生成初始化程序。

您要么必须为所有属性编写自己的初始化程序,要么可以删除自定义的初始化程序。

关于arrays - swift 2 : Extra argument in call for array and struct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33322251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com