1

我是 swift 新手。我尝试学习许多教程,但仍然无法找到解决方案。我想将存储在数组中的值传递给函数。

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) {
}
4

1 回答 1

0

这很容易,函数调用是错误的。它应该是

addDiaryList(track:track!)

第一个track代表函数中的参数名称,第二个代表您在上面分配的两行变量。

但我认为你在这里做了很多无用的电话,它可能是:

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

func addDiaryList(track:String) {
}

for trackId in trackList{
    addDiaryList(track: trackId)
}
于 2017-10-31T06:59:45.137 回答