A UIKit Xcode project targeted for only iOS, it has 3 targets for different build configurations.
When I add a swiftui file it builds and runs fine, but I can’t see the simplest previews I get Cannot preview this file - un expected error occurred
Exact diagnostics is
HumanReadableSwiftError
ProviderError: ProviderError: noPreviewInfos(runDestination: Simulator - iOS 15.2 | iphonesimulator | x86_64 | iPhone 13 Pro Max | Apple Watch Series 6 - 44mm, thunkConfiguration: <IDEBuildOperationConfiguration buildCommand: 8, buildParameters: <IDEBuildParameters:0x7fe4bffe2f40:action=build:command=<IDEConcretePrimitiveSchemeCommand:0x7fe4bb382500:Run>:config=Release:dest=iPhone 13 Pro Max:arch=x86_64:workspaceArena=<IDEWorkspaceArenaSnapshot: 0x7fe4bbbbf2b0>:
overridingProperties=(
{ // Preview overrides (immutable)
DSTROOT = ใ๐๐ถ๐๐ฒ๐ฟ๐ฎ๐น๐ฆ๐๐ฟ๐ถ๐ป๐ด:/Users/x/Library/Developer/Xcode/DerivedData/MayApp-ezbgeibumcswldddlegmcbpnukij/Build/Intermediates.noindex/Previews/MayApp/ReleaseProductsใ
ENABLE_PREVIEWS = ใYESใ
OBJROOT = ใ๐๐ถ๐๐ฒ๐ฟ๐ฎ๐น๐ฆ๐๐ฟ๐ถ๐ป๐ด:/Users/x/Library/Developer/Xcode/DerivedData/MayApp-ezbgeibumcswldddlegmcbpnukij/Build/Intermediates.noindex/Previews/MayApp/Intermediates.noindexใ
SYMROOT = ใ๐๐ถ๐๐ฒ๐ฟ๐ฎ๐น๐ฆ๐๐ฟ๐ถ๐ป๐ด:/Users/x/Library/Developer/Xcode/DerivedData/MayApp-ezbgeibumcswldddlegmcbpnukij/Build/Intermediates.noindex/Previews/MayApp/Productsใ
},
):
collectBuildTimeStatistics=NO
collectTimelineMetrics=NO>, executionEnvironment: Optional(<IDEExecutionEnvironment: 0x7fe52c865050>), singleFileToBuild: nil, buildLog: nil, parallelizeBuildables: true, dontActuallyRunCommands: false, buildImplicitDependencies: true, skipDependencies: false, buildables: Optional([<Xcode3TargetProduct:0x7fe549f34fa0:MayApp.app blueprint:<Xcode3Target:0x7fe4bb385f20:MayApp>>]), subsetOfBuildables: nil, buildDescriptionID: nil, scheme: Optional(<IDEScheme:0x7fe4baea1490:'MayApp'>), schemeTask: 0, clientInfo: nil>, blueprintName: MayApp Staging, sourceFilePath: /Users/x/Git/MayApp/options/MayApp_ios/MayApp/Application/Exploration/ProfileSettings/ProfileSettingsView.swift, thunkVariantSuffix: __XCPREVIEW_THUNKSUFFIX__)
Things I have tried:
I updated macos and xcode to latest version (Xcode Version 13.2.1)
- SwiftUI file is added to all 3 targets
- Erased the simulators
- Deleted derived data
- Restarted the mac and xcode multiple times
- Tried setting the Build Active Architectures to both Yes and No
- Excluded architecture arm64
sudo xcodebuild -license accept
- Tried setting
ENABLE_PREVIEWS = YES
for all targets as well
Nothing works
Weirdly it also complained about the UI tests when I added SwiftUI file without running the test, but I commented out those files now.
2
Answers
Usually, this kind of issue gets resolved by clearing up the derived data folder. Below are the steps I usually follow:
What libraries/packages are you using? I encountered a similar error for a long period of time. I was using the Package Manager to implement Firebase functionality, and was able to compile/run normally but not for previews or simulators specifically. None of the excluded architecture stuff worked for me either. Instead, I had to switch back to using Cocoapods rather than the Package Manager, at least for Firebase specifically. After some fiddling, I’ve never had an issue since and run previews all the time. Apologies if this is not useful but you didn’t provide much context.