apple/Docs, iOS, Swift

[XCode 15.0 beta] Preview Macro Bug

lgvv 2023. 6. 8. 12:06

Preview Macro Bug

 

🚨 Bug

 

CompileDylibError: Failed to build ContentView.swift

 

Compiling failed: main actor-isolated let 'previewContainer' can not be referenced from a non-isolated context

 

 

✅ Solution

 

1.

#Preview {
    MainActor.assumeIsolated {
        ContentView()
            .frame(minWidth: 500, minHeight: 500)
            .modelContainer(previewContainer)
    }
}

 

2.

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

 

3.

#Preview { @MainActor in
    ContentView()
        .frame(minWidth: 500, minHeight: 500)
        .modelContainer(previewContainer)
}

 

5.

#Preview {
    MainActor.assumeIsolated {
        ContentView()
            .frame(minWidth: 500, minHeight: 500)
            .modelContainer(previewContainer)
    }
}

 

 

 

[forum link]

https://developer.apple.com/forums/thread/731134 

 

Error after adding previewContaine… | Apple Developer Forums

I asked Chatgpt for this question, and it told me this: #Preview { MainActor.assumeIsolated { ContentView() .frame(minWidth: 500, minHeight: 500) .modelContainer(previewContainer) } } It worked.

developer.apple.com

 

'apple > Docs, iOS, Swift' 카테고리의 다른 글

[UIKit] UILabel Inset  (0) 2023.06.23
[WWDC23] Meet MapKit for SwiftUI  (0) 2023.06.18
[Swift] 커링(Currying)  (1) 2023.02.28
[iOS] UIImage.Orientation  (0) 2022.12.09
Swift HTML 코드 로드하기  (0) 2022.10.06