我在做A Swift Tour。_和..在for循環中意味着什麼?
一:
我沒有得到Generics
功能的邏輯。它的Design Patterns
?對巡演的解釋看起來非常短暫和不清楚。
二:
在這種PICE的代碼創建一個通用的功能,
func repeatItem<Item>(item: Item, numberOfTimes: Int) -> [Item] {
var result = [Item]()
for _ in 0..<numberOfTimes { //im not getting this line (?)
result.append(item)
}
return result
}
repeatItem("knock", numberOfTimes:4)
我不明白這個語法非常好,拿什麼_
,..
,並在同<
行,爲什麼使用?
「_」意味着你不會爲不會使用 –
爲什麼我不使用'一個VAR需要一個名字爲_ in _'而不是'for _ in ..'使它們獨一無二?什麼是泛型@LeoDabus – AndreL