3

while exploring the swiftUI and creating my first swiftUI app in Xcode, it is throwing an error for the preview saying - Cannot preview in this file, Cannot connect to [Device Name]. While it's working fine in simulator.

In order to troubleshoot, I've already tried all the basic hacks like -

  • Deleting the DerivedData,
  • Uncheck Automatically Refresh Canvas [As suggested in some stackOverflow answers],
  • Rebooting the mac[Intel Based]/device,
  • Updating the latest macOS [currently it's 12.5.1],
  • Removing the Xcode completely,
  • Installing the latest Xcode from scratch [Currently it's Xcode v14.0],
  • Tried removing all the simulators and installing a fresh one.

On the stackOverflow, there are few similar questions asked, but the reason is different after the title "Cannot preview in this file ..... "

attaching the screenshot of newly created test project >>

Preview Error Preview Diagnostic Description

Please suggest with any solution which can help to resolve the issue, Thanks in advance

Mohit G.
  • 1,157
  • 2
  • 12
  • 22
  • After trying almost everything (which didn't help me of-course) I format my machine and fresh install Xcode worked for me :) – Mohit G. Dec 20 '22 at 12:45

2 Answers2

0

Just quit Xcode and reopen. On the top of Xcode you will see loading animation like "Preparing simulator for Previews". After that your preview will work

nazar41
  • 11
  • 2
0

Just encountered this issue with Xcode 14.2, really frustrating. Resolved by uninstalling Xcode completely and reinstalling from app store. Currently running Xcode 14.3.1 and previews work just fine.

sirATL
  • 71
  • 1
  • 7