Skip to content

Instantly share code, notes, and snippets.

@joehinkle11
Created April 21, 2021 02:40
Show Gist options
  • Save joehinkle11/1f653227abcf204b5daa9145056879ee to your computer and use it in GitHub Desktop.
Save joehinkle11/1f653227abcf204b5daa9145056879ee to your computer and use it in GitHub Desktop.
Example showing how a stack overflow can be triggered by rendering a SwiftUI struct, even if the struct was already safely created
//
// ContentView.swift
// Shared
//
// Created by Joseph Hinkle on 4/20/21.
//
import SwiftUI
public struct ContentView: View {
let thisViewWillKillTheAppIfRendered = ContentView2()
@State var showContentView2 = false
public var body: some View {
Text("ContentView \(String(describing: thisViewWillKillTheAppIfRendered))")
Button("show ContentView2") {
showContentView2 = true
}
if showContentView2 {
thisViewWillKillTheAppIfRendered
}
}
}
public struct ContentView2: View {
public var body: some View {
VStack {
Text("ContentView2")
AnotherView()
}
}
}
public struct AnotherView: View {
public var body: some View {
VStack {
Text("AnotherView")
ContentView2()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment