1

im new to swift.I tried to follow many tutorials but still im not able to find a solution for it. I want to pass values stored in an array to a function.

let trackList = ["AC","BB"]    

for trackId in trackList{

 let ind = trackList.index(of: trackId)
 let index = trackList.startIndex.distance(to: ind!)
 let num = Int(String(describing: ind))
 let track = String(trackId)

 addDiaryList(track:String) //i keep getting error here saying: Cannot convert value of type 'String.Type' to expected argument type 'String'

}

func addDiaryList(track:String) {
}

1 Answers1

0

That's easy, the function call is wrong. It should be

addDiaryList(track:track!)

The first track stands for the parameter name in the function, the second one for the variable you assigned two rows above.

But I think you're doing a lot of useless calls here, it could rather be:

let trackList = ["AC","BB"]

func addDiaryList(track:String) {
}

for trackId in trackList{
    addDiaryList(track: trackId)
}
cldrr
  • 1,238
  • 14
  • 22