Xcode: Cannot preview in this file — Update failed
Issue
Playing with SwiftUI, I have faced this error few times and for the first time it took me some time to resolve it. So here is what I found as a solution to resolve this issue.
PotentialCrashError: Update failed your-project.app may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application. ================================== | Error Domain=com.apple.dt.UITestingAgent Code=-1 "failed to load library at path "/Users/**********/Documents/your-project/Build/Intermediates.noindex/Previews/your-project/Intermediates.noindex/your-project.build/Debug-iphonesimulator/your-project.build/Objects-normal/x86_64/DetailView.2.preview-thunk.dylib": Optional(dlopen(/Users/**********/Documents/your-project/Build/Intermediates.noindex/Previews/your-project/Intermediates.noindex/your-project.build/Debug-iphonesimulator/your-project.build/Objects-normal/x86_64/DetailView.2.preview-thunk.dylib, 2): no suitable image found. Did find: | /Users/**********/Documents/your-project/Build/Intermediates.noindex/Previews/your-project/Intermediates.noindex/your-project.build/Debug-iphonesimulator/your-project.build/Objects-normal/x86_64/DetailView.2.preview-thunk.dylib: open() failed with errno=1)" UserInfo={NSLocalizedDescription=failed to load library at path "/Users/**********/Documents/your-project/Build/Intermediates.noindex/Previews/your-project/Intermediates.noindex/your-project.build/Debug-iphonesimulator/your-project.build/Objects-normal/x86_64/DetailView.2.preview-thunk.dylib": Optional(dlopen(/Users/**********/Documents/your-project/Build/Intermediates.noindex/Previews/your-project/Intermediates.noindex/your-project.build/Debug-iphonesimulator/sketch-elements.build/Objects-normal/x86_64/DetailView.2.preview-thunk.dylib, 2): no suitable image found. Did find: | /Users/**********/Documents/your-project/Build/Intermediates.noindex/Previews/your-project/Intermediates.noindex/your-project.build/Debug-iphonesimulator/your-project.build/Objects-normal/x86_64/DetailView.2.preview-thunk.dylib: open() failed with errno=1)}
Solution
- Close Xcode
- Delete Build and DerivedData folders in your project path
- Restart your mac
- Build your project with the ▶ button
In case you don’t see the preview click Editor -> Canvas.
iOS Elements
You can find also the whole implementation in my UI kit — Download below.
Use discount code MOLCIK to get iOS Elements for $29.70 (70% off)
References
- [1] https://forums.developer.apple.com/thread/117487
- [2] https://stackoverflow.com/questions/56505356/cannot-preview-in-this-file-failed-to-launch-app-name
- [3] https://stackoverflow.com/questions/57340586/cannot-preview-in-this-file-app-name-app-may-have-crashed-on-xcode-11-beta-5
- [4] https://stackoverflow.com/questions/56506046/cannot-preview-in-this-file-swiftui-testing-app-may-have-crashed
- [5] https://stackoverflow.com/questions/56506046/cannot-preview-in-this-file-swiftui-testing-app-may-have-crashed