Created
April 21, 2021 02:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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