Hi, I am trying to use SwiftUI in my project where I was using UIKit only, until now. The problem is that Preview in Xcode is not working even for very simple View with Text("Hello World"). Code is correct and project is possible to build and run. Even when I try to select real device (real iPhone) I can see Preview in my device. But preview in simulator is not working. Can someone help me with this? I am attaching diagnostic from Xcode and file from ~/Library/Logs/DiagnosticReports/ Thanks for help
SwiftUI Preview not rendering
Hi,
Sorry to hear you are having problems getting previews working. This error can often indicate an app bundle that is missing the required architecture slice in its binary. Do you have any custom build settings in the Architectures section?
If you'd like us to help you investigate then the best next step will be to file a feedback with diagnostics so we can take a look at the rich data it includes.
Steps to generate helpful diagnostics:
- Download and install the logging profile on all devices involved. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift
- Reproduce the issue
- Click the "Diagnostics" button in the error banner in Previews' Canvas area (or if the banner is missing you can use the menu: Editor > Canvas > Diagnostics)
- In the sheet that appears, click "Generate Report" in the bottom left of the sheet
- Attach (or make from the folder) the resulting zip file to the bug (will be named something like
previews-diagnostics-0123456789.zip
) - Generate the sysdiagnose(s) and attach those too
Hi, I tried to remove most of the packages used via SPM and remove almost all custom code from AppDelegate but it didn't helped. Rest of libraries are not so easily removed so I am not sure if it's them or something else. I am attaching generated report from Diagnostics popup for Preview. And I am also adding link to sysdiagnoses but I wasn't sure if I am done this correctly. I used macOS manual because it's happening in Xcode for iOS simulator and with iOS real device Preview it's working correctly. Thanks for help
Thank you for your assistance. It took me a while, but I finally figured out where the issue was. I had to reduce the entire project to its bare minimum, and only then did I discover that the problem likely lay somewhere in the configuration. The issue was that 'arm64' was listed under Excluded Architectures. Since I inherited the project, I was unaware of this setting. It's a pity that Xcode doesn't indicate such reasons, as it would simplify the process of identifying problems.
@Brut Thank you for following up with what you discovered — you just saved me from going further down the black hole of debugging my failing previews!
Check if you are building simulator product under x86 arch.
ios17 simulator failed to launch app built with x86.
Consider use ios16
I have the same exact problem. And I can't attach the zip file that I created from the diagnostic report here either. My app is so sparse right now and I have no idea how to proceed further except to keep running and simulating the app every time I make changes which is working flawlessly.
It finally started working after like 15 minutes...dang...
I don't know if this will work for everyone, but worked for me...
I also have the arm64 added in the EXCLUDED_ARCHITECTURES because I need it due to a project dependency. Having it there make it possible to run my project in regular simulators (not the Rosetta ones), but apparently it doesn't work for the preview.
So I did the following:
In Product > Destination > Destination Architectures I selected "Show Both"
At the Canvas tab, in the device selector now all the devices appear duplicated. If I select the ones nearer to the bottom (yeah, specifically in this selector the "(Rosetta)" text doesn't appear) the preview works:
This allows me to use the preview and have the "arm64" added under the excluded archs.