🚨 0...items.count - 1 looks fine. It crashes on an empty array.
🤯 Empty list → count - 1 is -1 → the range is 0...-1
❌ Lower bound above upper bound → fatal error
✅ Write 0..<items.count instead
📭 Empty list → 0..<0 → zero iterations, no crash
🧵
🚨 0...items.count - 1 looks fine. It crashes on an empty array. 🤯 Empty list → count - 1 is -1 → the range is 0...-1 ❌ Lower bound above upper bound → fatal error ✅ Write 0..<items.count instead 📭 Empty list → 0..<0 → zero iterations, no crash 🧵
0 vue
Publié le 19/11/2026 05:29
1:02
🚨 0...items.count - 1 looks fine. It crashes on an empty array.
🤯 Empty list → count - 1 is -1 → the range is 0...-1
❌ Lower bound above upper bound → fatal error
✅ Write 0..<items.count instead
📭 Empty list → 0..<0 → zero iterations, no crash
🧵
🎯 Positions of a collection? Always 0..<count
💡 The second value of ..< is "the index after the last item", which is exactly what count is.
Want to learn more? Subscribe to my channel 👇
www.youtube.com/@CaneAllesta...