I have a brand new 21 Macbook Pro with the M1 Pro chip. I installed Xcode from the app store, and I have also installed Xcode beta. I am completely up to date on Monterey as well.
I am building a swift UI app and I cannot get preview to work at all.
I get the following error.
== PREVIEW UPDATE ERROR:
MessageSendFailure: Message send failure for send previewInstances message to agent
==================================
| RemoteHumanReadableError
|
| LoadingError: failed to load library at path "/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib": Optional(dlopen(/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib, 0x0002): tried: '/Users/brandon/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Products/Debug-iphonesimulator/SwiftUIView.2.preview-thunk.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib' (no such file), '/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib' (no such file), '/usr/lib/SwiftUIView.2.preview-thunk.dylib' (no such file))
I have tried to reinstall xcode, reboot you name it.
I can get simulator to work…
Any ideas?
4
Answers
I had the same problem and found a solution here:
https://developer.apple.com/forums/thread/691237
I was not signed in to GitHub so as suspected, it does not play a role.
It seems Xcode got in to an invalid state. I suspect that simply disabling and enabling automatic signing would resolve the issue but I also cleared the Container folder for my project as suggested in the post.
Same issue and resolved it by change Mac’s user name to lowercase.
Username->username
Nothing I tried worked, including running:
sudo xcodebuild -license
in the terminalOnly when I toggled Automatically refresh canvas (Editor > Canvas) I got preview back.
Preview was failing on a new default projects as well.
I had the same problem because I downloaded a GitHub project (an existing
SwiftUI
project) and I didn’t create a newSwiftUI
project from scratch. I notice theSwiftUI
view doesn’t had thePreviewProvider
struct
at the bottom:After adding the
PreviewProvider
struct
,Xcode
showed the Preview.