Advertisement
Larme

Untitled

Feb 6th, 2023
1,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.58 KB | None | 0 0
  1. var array = ["First Cell", "Second Cell", "Third Cell", "Fourth Cell", "Fifth Cell"]
  2. let total = array.count + array.count / 3
  3. for i in 0..<total {
  4.     print("Row index: \(i)")
  5.     if i % 3 == 0 &&  i != 0 {
  6.         print("Add Cell")
  7.     } else {
  8.         let data = array[i]
  9.         print(data)
  10.     }
  11. }
  12.  
  13. Output:
  14.  
  15. Row index: 0
  16. First Cell
  17. Row index: 1
  18. Second Cell
  19. Row index: 2
  20. Third Cell
  21. Row index: 3
  22. Add Cell
  23. Row index: 4
  24. Fifth Cell
  25. Row index: 5
  26. Swift/ContiguousArrayBuffer.swift:575: Fatal error: Index out of range //Because, you try to access array[5] which doesn't exists
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement