skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. Same issue and resolved it by change Mac’s user name to lowercase.
    Username->username

    Login or Signup to reply.
  3. Nothing I tried worked, including running:

    • sudo xcodebuild -license in the terminal
    • Deleting derived data
    • Sign in again to GitHub
    • Restarts

    Only when I toggled Automatically refresh canvas (Editor > Canvas) I got preview back.
    Preview was failing on a new default projects as well.

    Login or Signup to reply.
  4. I had the same problem because I downloaded a GitHub project (an existing SwiftUI project) and I didn’t create a new SwiftUI project from scratch. I notice the SwiftUI view doesn’t had the PreviewProvider struct at the bottom:

    struct SwiftUIView_Previews: PreviewProvider {
        static var previews: some View {
            SwiftUIView()
        }
    }
    

    After adding the PreviewProvider struct, Xcode showed the Preview.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search