我在這里看到了一些關于相同 Thread 1 警告的帖子,但是沒有任何特定于我的代碼(或者至少不是我能看到的)。
錯誤是:執行緒1:EXC_BAD_ACCESS(代碼=2,地址=0x7ffee99cdfd8)
問題是:XCode 構建器或預覽都無法正常作業,因此無法構建。@main 是錯誤在 App 視圖中出現的地方。
import SwiftUI
@main
struct WApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
這是內容視圖代碼:
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()
}
}
任何幫助都會很棒。如果代碼的長度是問題,我已經嘗試過重構,但沒有奏效。謝謝。
uj5u.com熱心網友回復:
很難相信 ?? 但是這次崩潰是由打字錯誤引起的,它產生了有效的(即“可編譯”)代碼,但它隨后陷入某種無限回圈并可能耗盡記憶體?:
Image(systemName: "cloud.sun.fill")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
frame(width:40, height:40) // <-- missing dot!
所以你應該把它改成:
Image(systemName: "cloud.sun.fill")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:40, height:40)
編輯
忍不住添加這個 ?? 突然出現在我的腦海中:
因為需要一個點,應用程式丟失了
由于需要一個應用程式,所以開發人員丟失了
由于需要開發人員而丟失了業務
由于需要業務而丟失了市場
由于需要市場而丟失了國家
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/338929.html
上一篇:無法在xcworkplacecocoapods中匯入依賴項
下一篇:swift5中的模糊深度
