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
'project > 개발 업무' 카테고리의 다른 글
SwiftUI로 Placeholder가 존재하는 TextField 설계 팁 (UIKit호환) (1) | 2024.09.29 |
---|---|
[Xcode 16 Beta] Could not download and install iOS 18.0 Simulator runtime with Xcode 16.0 beta (0) | 2024.06.12 |
Lottie 리소스 문제로 앱이 초기화되는 현상 (0) | 2022.07.12 |
iOS RxDelegateProxy 만들어보기 #2 (StarScream + RxProxy) (0) | 2022.01.12 |
iOS 앱 이름 변경하기 (1) | 2021.11.09 |