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
'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 |