12

I am trying to play around with swiftUI in Xcode 11 and macOS Catalina. BUT After creating a new Project, there is a boiler plate code with a Text that says hello World. I want to have a live preview of this simple welcome message in the canvas by the side of the code.

When i hit the resume button : It says :

Cannot Preview in this file - Failed to launch [App Name]

I've tried hitting the diagnostic button that generated a report to send it to APPLE saying:

[FailedToLaunchError(url: file:///Users/naive/Library/Developer/Xcode/DerivedData/first_swiftUI-dymizjogcbtouhclgjhhefagmcqo/Build/Intermediates.noindex/Previews/first_swiftUI/Products/Debug-iphoneos/first_swiftUI.app, underlying: Error Domain=NSOSStatusErrorDomain Code=-10661 "(null)" UserInfo={_LSLine=3554, _LSFunction=_LSOpenStuffCallLocal}, failureCategory: UVFoundation.FailureCategory.infrastructureFailure) ]

Here's the code, It is the default code that comes with new project created with Xcode 11 and SwiftUI option checked:

import SwiftUI

struct ContentView : View {
    var body: some View {
        Text("Hello World")
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

I expect the canvas to show up and display live preview of my code. The canvas is not showing up !!

There are two warning messages generated :

:0: warning: imported declaration 'UITableViewDiffableDataSourceCellProvider' could not be mapped to 'UITableViewDiffableDataSourceReference.CellProvider'

:0: warning: imported declaration 'UICollectionViewDiffableDataSourceCellProvider' could not be mapped to 'UICollectionViewDiffableDataSourceReference.CellProvider'

other than that, My iPad 11"with iPadOS beta runs the app, The simulator is working as well

Parajuli Roman
  • 551
  • 1
  • 6
  • 15
  • 2
    I got it fixed by assigning command line tools to xcode 11, it was set to previous version of xcode 10. Preferences > location > commandLine tools [drop down] > select xcode 11 – Parajuli Roman Jun 08 '19 at 10:12
  • Two suggestions? (I didn't have this issue but found your question and answer to be potentially valuable to others who may have the same issue.) #1. Reformat your question with good markdown. The errors/warnings are simple text and are hard to read. #2. Post your solution as an answer instead of a comment. (That's perfectly okay to do!) I'd definitely upvote it. –  Jun 08 '19 at 10:23
  • Thank you @dfd I filled up the text boxes shown by stackoverflow with my questions as they appear sequentially in a VStack – Parajuli Roman Jun 08 '19 at 18:06
  • I edited your question, placing "markdown quotes around 4 passages. One last comment - with regards to the two warnings your received, be *very* aware that you are using a "beta 1" version of something brand new, and as noted in the link, *"For example, if you make a mistake in your SwiftUI code you will often get almost incomprehensible error messages."* Hopefully this will improve with future betas. https://wwdcbysundell.com/2019/interviews/paul-hudson/ –  Jun 08 '19 at 20:26
  • thankYou dfd [markdown quotes] i will remember it. – Parajuli Roman Jun 11 '19 at 05:58
  • Xcode 11.3 error description drops reference to `failureCategory `. Now looks like: `FailedToLaunchError: Failed to launch demo.app | Error Domain=NSOSStatusErrorDomain Code=-10661 "(null)" UserInfo={_LSLine=3590, _LSFunction=_LSOpenStuffCallLocal}` – RobLabs Jan 04 '20 at 18:00

15 Answers15

24

I encountered this UVFoundation.FailureCategory.infrastructureFailure when starting an iOS app with SwiftUI and then checking the Mac target in the project properties (i.e., using Catalyst to create a cross-platform app). When I did this the default device changed to "My Mac" and preview stopped working, yielding this error in the diagnostic window.

Preview for the Mac target doesn't seem to be supported—you have to select some iOS target ("Generic iOS Device" works just fine for me). Tested on Mojave beta 5 with Xcode 11 beta 5. From the Xcode 11 beta 5 release notes: "Xcode 11 doesn’t support working with SwiftUI in a Mac Catalyst app. (41416222, 51201699)"

"My Mac" selected, it doesn't work! "My Mac" selected, it doesn't work!

Working with "Generic iOS device" selected. Working with "Generic iOS device" selected

Brett
  • 4,341
  • 2
  • 19
  • 17
  • 3
    This fixed it for me; thank you! Crazy that it can't preview with a Mac device selected, seeing as macOS 10.15 supports SwiftUI, just the same as iOS 13 does. – TheNeil Nov 23 '19 at 23:38
12

I got it fixed by assigning command line tools to Xcode 11, it was set to previous version of Xcode 10.

Go to : Preferences > location > commandLine tools [drop down] > select Xcode 11

shim
  • 9,289
  • 12
  • 69
  • 108
Parajuli Roman
  • 551
  • 1
  • 6
  • 15
6

Check Diagnostic reports on path ~/Library/Logs/DiagnosticReports.
Open fileName.crash file (fileName is the file which causing crash) and search Application Specific Information
Fix your code as per the information

Kishore Suthar
  • 2,943
  • 4
  • 26
  • 44
5

I just quit and reopened Xcode with the same project and the preview started working again.

If that doesn't work try Command + K to clean the project, then tap "Resume" to try again.

shim
  • 9,289
  • 12
  • 69
  • 108
Kiran Jasvanee
  • 6,362
  • 1
  • 36
  • 52
3

I had this issue (Cannot preview in this file -- Update failed) on Catalina 10.15.5 with Xcode 11.5 when trying to preview a Canvas for MacOS target with a vanilla SwiftUI project template after applying cocoapods and Xcode suggestions.

None of the already listed solutions worked for me.

I got a hint in the "Diagnostics" saying "... code signature in (.../Data/ContentView.2.preview-thunk.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))} ..."

This solved the issue: Project > TARGETS > MacOSTarget > Signing Certificate > Development

(Previously was "Sign to Run locally")

shim
  • 9,289
  • 12
  • 69
  • 108
fredfred
  • 196
  • 2
  • 5
1

For me pick anything but the 11 Pro max and it will work.

Jevon Charles
  • 644
  • 1
  • 7
  • 12
1

If you click on your project name to the right of the run/ 'play' button you can switch over to the iOS options. It is initially set to macOS.

Dharman
  • 30,962
  • 25
  • 85
  • 135
1

I had the same problem and changing the location was what worked for me. I changed it from "Relative to Group" to "Relative to Project" and the preview came up!

In this link, you can find more information

Juanes30
  • 2,398
  • 2
  • 24
  • 38
  • Worked for me as well, but I could actually change it back to "Relative to Group" afterwards and it still worked. So apparently changing that setting triggered internal stuff and once that has happened, it just works. ‍♂️ – Mischa Sep 23 '21 at 12:44
0

Open Terminal and type the following command

sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer

and then run sudo xcodebuild -license. Type agree and hit return key to the license. Also select Xcode 11 for Command Line tools from Preference -> Location -> CommandLine in Xcode. This worked for me.

Vinoth Vino
  • 9,166
  • 3
  • 66
  • 70
0

In my case, I checked generated Diagnostics report and it showed

" Dyld Error Message: app was built for iOS 13.2 which is newer than this simulator 13.1 "

So I changes the iOS Deployment target to 13.1 from build settings.

Tap on resume and it worked for me.

chitra
  • 1
  • 1
0

For my case it was because I unintentionally tried to build on real device instead of the simulator. By selecting a simulator from the list, it got up and running again.

Malloc
  • 15,434
  • 34
  • 105
  • 192
0

I had the same problem and I found it was a runtime error that was causing this error because the project was compiling successfully. The error was caused by an image that was not referenced within the project.

pableiros
  • 14,932
  • 12
  • 99
  • 105
0

Same error

Try to:

Editor > Canvas > Refresh rate

0

If you getting error "Cannot Preview in this file".

Try this first :

close the xcode window

Right click on the icon and select Quit

Reopen and the issue will mostly be fixed.

This works for most of the issues in xcode, before you try anything else try to close the window, force exit and then reopen the project.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
-1

None of the above worked for me - but I did find a way...

  1. Copy the content of the offending file (eg ContentView.swift).
  2. Delete the offending file from your project.
  3. Create a new 'SwiftUI View' and rename it back to whatever file you deleted.
  4. Paste the content you copied in step 1 back in.
  5. Click resume in the canvas.
Leo
  • 1
  • 1