Hello, this is my first real Swift project, and I have ran into an issue. For some reason, when running my (WIP) project, having "Enable Results" set to on causes my project to not behave properly, run slowly, and eventually crash.
Some Notes: Setting "Enable Results" to off fixes the issue completely, and I know that I could just put in a comment asking to disable it, but I am concerned that if the judges miss that then I will get disqualified
I am using the Swift Playgrounds App, not Xcode
I am aware that NavigationView does not work on the iPadOS version of Playgrounds, this is a macOS Playgrounds project
What happens when I run my project with "Enable Results" set to on is that the default view that is shown in the NavigationView is not shown and the app runs slowly. When you try to select one of the Sidebar Items, the project eventually shows the default view inside the NavigationView, and then crashes, showing the generic "There was a problem encountered while running this Playground. Please check your code for mistakes" error message.
I am 90% sure that the problem lies in the NavigationView, but I went ahead and put in the rest of my code in case the problem lies elsewhere
Any help would be extremely appreciated! Thanks!
import SwiftUI
import PlaygroundSupport
struct mainView: View {
var body: some View {
navView()
}
}
struct navView: View {
@State private var selectedView: Int?
var body: some View {
ZStack(alignment: Alignment(horizontal: .center, vertical: .center)) {
NavigationView {
List {
Section(header: Text("SplashScreen")) {
NavigationLink("SplashInfo", destination: splashInfoDetailView(), tag: 0, selection: self.$selectedView)
NavigationLink("SplashInfoContainer", destination: splashInfoContainerView(), tag: 1, selection: self.$selectedView)
NavigationLink("SplashTitle", destination: splashTitleView(), tag: 2, selection: self.$selectedView)
NavigationLink("SplashScreen", destination: splashScreenView(), tag: 3, selection: self.$selectedView)
}
.onAppear() {
self.selectedView = 3
}
}
}
}
}
}
struct splashInfoDetailView: View {
var title: String = "Test Title"
var subTitle: String = "Test Subtitle"
var imageName: String = "exclamationmark.triangle.fill"
var body: some View {
HStack(alignment: .center) {
Image(systemName: imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 35, alignment: .center)
.font(.largeTitle)
.padding(10)
VStack(alignment: .leading) {
Text(title)
.font(.headline)
Text(subTitle)
.font(.body)
}
}
}
}
struct splashInfoContainerView: View {
var body: some View {
VStack(alignment: .leading) {
splashInfoDetailView(title: "redacted", subTitle: "redacted", imageName: "swift")
splashInfoDetailView(title: "redacted", subTitle: "redacted", imageName: "swift")
splashInfoDetailView(title: "redacted", subTitle: "redacted", imageName: "swift")
splashInfoDetailView(title: "redacted", subTitle: "redacted", imageName: "swift")
}
.padding(.horizontal)
}
}
struct splashTitleView: View {
var body: some View {
VStack(alignment: .center) {
Image(systemName: "swift")
.resizable()
.foregroundColor(.red)
.aspectRatio(contentMode: .fit)
.frame(width: 125, alignment: .center)
Spacer(minLength: 15)
Text("redacted")
.font(.system(size: 27))
.fontWeight(.black)
Text("redacted")
.font(.system(size: 27))
.fontWeight(.black)
}
}
}
struct splashScreenView: View {
var body: some View {
ScrollView {
VStack(alignment: .center) {
Spacer(minLength: 20)
splashTitleView()
Spacer(minLength: 20)
splashInfoContainerView()
Spacer(minLength: 30)
}
}
}
}
PlaygroundPage.current.setLiveView(mainView())