New to coding so teaching myself through Swift and the Intro to App Development with Swift book.
Whilst learning about Arrays and Loops, I am unable to see the index of an array in a list? How do I do this?
Note: The exercise says you can use the Show Result Button in the results sidebar and see the indices in the inline view.
Any help is appreciated, plus any tips for coding as I'm new and looking to create a number of apps, including games.
Thanks - Harrison.
Whilst learning about Arrays and Loops, I am unable to see the index of an array in a list? How do I do this?
Note: The exercise says you can use the Show Result Button in the results sidebar and see the indices in the inline view.
Any help is appreciated, plus any tips for coding as I'm new and looking to create a number of apps, including games.
Thanks - Harrison.
Not sure of whet you want exactly to do. You should show the code on which your question is based.
But, if you have an array, you can loop through elements and their index:
And get
index 0 item a
index 1 item b
index 2 item c
index 3 item d
But, if you have an array, you can loop through elements and their index:
Code Block let myArray = ["a", "b", "c", "d"] for (index, item) in myArray.enumerated() { print("index", index, "item", item) }
And get
index 0 item a
index 1 item b
index 2 item c
index 3 item d