Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var array = ["First Cell", "Second Cell", "Third Cell", "Fourth Cell", "Fifth Cell"]
- let total = array.count + array.count / 3
- for i in 0..<total {
- print("Row index: \(i)")
- if i % 3 == 0 && i != 0 {
- print("Add Cell")
- } else {
- let data = array[i]
- print(data)
- }
- }
- Output:
- Row index: 0
- First Cell
- Row index: 1
- Second Cell
- Row index: 2
- Third Cell
- Row index: 3
- Add Cell
- Row index: 4
- Fifth Cell
- Row index: 5
- 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