I made an array and init in separate class. When I made init(index: Int) to try to get values, then "Extra argument (entry) in call" appears as indicated in the codes. I'm still a new learner. After looking for a clue, I couldn't get meaningful solutions. I really appreciate your guidance.
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!
}
}
So I took the advice and almost there..., but I stuck another problem. It now says "Argument labels '(named:)' do not match any available overloads" at the line of suggestionList = UIImage!(named: iconName). And the array insist that cannot convert String to UIImage. I profoundly appreciate your advice. Thanks!
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]
}
}
The compiler only auto-generates the initialiser for all properties when there's not any custom initialiser (which there is in your case).
You either have to write your own initialiser for all properties or you can remove your custom one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.