This error only started happening once I made a second .swift view. This is also happening to another piece of code I'm making and it also started when I added a second .swift file. I'm running Xcode version 12.4 on macOS Catalina 10.15.7 The code for the content view:
import SwiftUI
struct ContentView: View {
var body: some View {
GifImage(name: "boulder.gif")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
The code for the other view:
import SwiftUI
import WebKit
struct GifImage: UIViewRepresentable {
private let name: String
init( name: String) {
self.name = name
}
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
let url = Bundle.main.url(forResource: name, withExtension: "gif")!
let data = try! Data(contentsOf: url)
webView.load(data, mimeType: "image/gif",
characterEncodingName: "UTF-8",
baseURL: url.deletingLastPathComponent()
)
return webView
}
func updateUIView( _ uiView: WKWebView, context: Context) {
uiView.reload()
}
}
struct GifImage_Previews: PreviewProvider {
static var previews: some View {
GifImage(name: "boulder")
}
}
I tried displaying a GIF in my app.
Keep as less dependencies as possible for the view. Run "Product -> Build" before previewing - it helps to build missing files (preview needs complete app compilation).