2

I want to start loop through array at index (say “5” or any other) instead of beginning of the array in swift

for (index, value) in array.enumerate() {
  // do something 
}
1

2 Answers 2

3

Use dropFirst to ignore the first items:

for (index, value) in array.enumerated().dropFirst(5) {
    // your code here
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use the where clause

for (index, value) in array.enumerate() where index > 4 { ...

By the way: Update your Swift version. Swift 2 is dead

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.