Categories
iOS Development

Working with Arrays in SwiftUI

One of the most common things you’ll find yourself doing when building UI is dealing with arrays of data. When all you want to do is read from an array this is fairly straightforward. Things get more complicated when you want to know an item’s offset, index, or to gain mutable access via bindings. Here […]

Categories
iOS Development

Quick tip: Avoid crash when using ForEach & Bindings in SwiftUI

If you’ve played around with ForEach and .onDelete in SwiftUI you might have encountered a crash due to ‘Index out of range‘ when you delete elements that are referenced with a binding (eg. a Toggle within your ForEach closure) This occurs due to a race condition of sorts… SwiftUI is trying to read from the […]