Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 805
Parajuli Roman Avatar asked Jun 08 '19 10:06

Parajuli Roman


5 Answers

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.

like image 196
Kiran Jasvanee Avatar answered Oct 19 '22 18:10

Kiran Jasvanee


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

like image 21
Juanes30 Avatar answered Sep 30 '22 21:09

Juanes30


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

like image 24
Brett Avatar answered Oct 19 '22 20:10

Brett


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

like image 12
Parajuli Roman Avatar answered Oct 19 '22 20:10

Parajuli Roman


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

like image 6
Kishore Suthar Avatar answered Oct 19 '22 19:10

Kishore Suthar