Jr795
Jr795

Reputation: 799

XCode 13 SwiftUI "Cannot preview in this file - Message send failure for update"

whilst working on an existing XCode project, the simulator began consistently crashing. The preview window will not show the current file, with a red banner and the below error:

MessageSendFailure: Message send failure for update
==================================
|  MessageError: Connection interrupted

I have tried:

Nothing seems to be working. Does anyone know how to resolve this? It was working fine previously, seems to have broken at random.

I am using XCode 13.2.1

Edit: This is only affecting this app. Other projects still work fine

Upvotes: 7

Views: 9585

Answers (6)

Roshani
Roshani

Reputation: 21

  1. close Xcode and simulator.
  2. Delete Previews inside (but not the Preview folder itself)

/Users/me.myself/Library/Developer/Xcode/UserData/Previews run

  1. killall -9 com.apple.CoreSimulator.CoreSimulatorService

4.Restart Xcode

Upvotes: 0

Yuri Petrosyan
Yuri Petrosyan

Reputation: 1

Changing Derived data and Archives to "Default" worked for me.

I was using an external SSD to store the file and I had a custom path. After changing it in Settings/Locations it worked

Upvotes: 0

Feldur
Feldur

Reputation: 1169

In my case, I discovered that I had an unfortunate directory name collision - specifically, I had both

~/Library/Developer/Xcode/UserData/Previews/Simulator\ Devices

and

~/Library/Developer/Xcode/UserData/Previews/Simulator%20Devices

Deleting both of them solved the problem (in my case, the app widget worked in the simulator, but in the Xcode canvas, it would not launch.

Upvotes: 5

billsea
billsea

Reputation: 71

Changing the Derived Data location in XCode to "Default" appears to fix a related issue:

MessageSendFailure: Message send failure for update

==================================

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path...

XCode preferences

Upvotes: 0

Jr795
Jr795

Reputation: 799

I managed to fix this by wrapping the ContentView() call in the preview in a ZStack. This is a known bug caused by @FocusState when used in a top-level view that the preview window is rendering.

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ZStack {
            ContentView()
        }
    }
}

Credit: https://developers.apple.com/forums/thread/681571?answerId=690251022#690251022

Upvotes: 13

BPS
BPS

Reputation: 365

Quit XCode and run this terminal command:

xcrun simctl --set previews delete all

Then open your project, build it and try reloading the preview.

Upvotes: 10

Related Questions