0
我可以在Swift的for循環聲明中直接排除某個值或對象嗎?我試圖做這樣的事情,我循環索引,但我想在同一行中過濾掉someIndex
。Swift 3在For循環中排除Item
func updateTabsEnabled(isShowing: Bool) {
for index in 0..<viewControllers!.count, index != someIndex {
tabBar.items![index].isEnabled = !isShowing
}
}
我認爲這是可能的斯威夫特3,雖然我不記得和documentation似乎沒有把它放在那裏,雖然我可能已經錯過了它。
你不應該使用'0 ..
Alexander
@Alexander [半開放範圍](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html#//apple_ref/doc/uid/TP40014097-CH6-ID60) Apple的文檔中的示例使用array.count? – Alex
Apple的入門Swift資料不是代碼風格的仲裁者。我在這個網站上看到**無數個**問題,涉及到人們不小心輸入'0 ... array.count'。沒有理由不使用'array.indices'。 – Alexander