[英]Swift2: Extra argument in call for array and struct
我在單獨的類中創建了數組和init。 當我使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!
}
}
所以我接受了建議,幾乎到了那里...,但我遇到了另一個問題。 現在,在proposalList = UIImage!(命名為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]
}
}
只有在沒有任何自定義初始化程序(您有這種情況)時,編譯器才會自動為所有屬性生成初始化程序。
您必須為所有屬性編寫自己的初始化程序,或者可以刪除自定義的初始化程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.