Home > Software engineering >  XCode Swift: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee99cdfd8)
XCode Swift: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee99cdfd8)

Time:10-28

I've seen a few posts on here about the same Thread 1 warning, however nothing that's specific to my code (or at least not that I can see).

The error is: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee99cdfd8)

The issue is: neither the XCode builder or preview are working, making it quite impossible to build. The @main is where the error crops up in the App view.

import SwiftUI

@main
struct WApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Here is the content view code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            LinearGradient(gradient:  Gradient(colors: [.blue, .white]), startPoint: .topLeading, endPoint: .bottomTrailing)
                .edgesIgnoringSafeArea(.all)
            
            VStack {
                Text("California")
                    .font(.system(size: 32, weight: .medium, design: .default))
                    .foregroundColor(.white)
                    .padding()
                
                VStack(spacing:7) {
                Image(systemName: "cloud.sun.fill")
                    .renderingMode(.original)
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width:180, height:180)
                
                Text("76°")
                    .font(.system(size:70, weight: .medium))
                    .foregroundColor(.white)
            }
                HStack{
                    VStack(spacing:7) {
                    Text("Tuesday")
                            .font(.system(size: 20, weight: .medium, design: .default))
                            .foregroundColor(.white)
                            
                    Image(systemName: "cloud.sun.fill")
                            .renderingMode(.original)
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                        frame(width:40, height:40)
                    
                    Text("74°")
                            .font(.system(size: 20, weight: .medium, design: .default))
                            .foregroundColor(.white)
                            
                }
                }
                
                Spacer()
                
                
            
            }
        }
        
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Any help would be great. I've tried refactoring in case the length of the code is the issue, which hasn't worked. Thanks.

CodePudding user response:

It's hard to believe

  • Related