0

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]
}
}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Alternatively, you can move your custom initialiser into an extension, then the compiler will generate the default one for you.
@Abizern Nice! i didn't know that!
I should note that this only works when you don't put an access specifier on the struct. If you mark it as public, you need to write all your own initialisers anyway.
Thanks for your help. I still don't know how to write my own initializer... I didn't know this is a custom initializer... :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.