The For-In loop also works with arrays, as shown here:
var fruits = ["apple", "pineapple", "orange", "Json", "guava"] for f in fruits { print(f)//from w w w . ja va 2 s. c o m }
The preceding example iterates through the five elements contained within the fruits array and outputs them:
You can also iterate through a dictionary, as the following example shows:
var courses = [ "A": "a", "B": "b", "C": "c" ] for (id, title) in courses { print("\(id) - \(title)") }
You can iterate through a string and extract each character, as the following shows:
var str = "Swift Programming" for c in str {/*from ww w . j a v a 2 s. com*/ print(c) }