Strange Bugs In Playground Using SwiftUI

Last week, I’ve applied to Swift Student Challenge. During writing an application to submit I encountered some strange bugs in the Playground using SwiftUI.

There isn’t a lot of knowledge about the Playground on the internet and there is even less about SwiftUI and Playground. So, if you know why such bugs exit let me know via comments or contact section.

The first one, some kind of limit functions on tap gesture. If I put two functions inside tap gestures app crashes even if the second one is empty.

It works examples:

// Some view
.
onTapGesture {
    self.speak()
}

It crashes:

//  Some view
.
onTapGesture {
    self.speak()
    self.removeLast()
}

The seconds one is changing values of primitive types. For example, changing the value of string and bool crashes the app. To workaround that problem, I used array with a single string element and .toggle() to change bool value.

It crashes:

self.boolVariable = false
self.stringVariable = “newString”

It works:

self.boolVariable.toggle()
self.stringVariable[0] = “newString”

I don’t have any solutions for them, only workarounds.