SwiftUI Preview - Undefined symbols for architecture arm64
Starting on Xcode 15.3 and 15.4 my SwiftUI Previews stopped working with the following error:
== PREVIEW UPDATE ERROR:
LinkDylibError: Failed to build ContentView.swift
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found
Undefined symbols for architecture arm64:
"static MyLibrary.DisplayUtil.getText() -> Swift.String", referenced from:
closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o
"type metadata accessor for MyLibrary.DisplayUtil", referenced from:
closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
After much trial and error, I narrowed it down to my SwiftUI views using properties or functions inside components in Swift Packages.
This is a simple example of my Swift Package:
public class DisplayUtil {
public func getText() -> String {
return "Text"
}
public static func getText() -> String {
return "Text"
}
}
And my SwiftUI View
import SwiftUI
import MyLibrary
struct ContentView: View {
var body: some View {
VStack {
Text(DisplayUtil.getText())
}
.padding()
}
}
#Preview {
ContentView()
}
The same code works fine on Xcode 15.2
Link to the sample project:
https://www.icloud.com/iclouddrive/0c00AD0esi2PwqqiRggokfwGw#Demo%5FBroken%5FPreview
Is anybody else having a similar issue?
MacBook Pro 16″, macOS 12.6