7

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.

SpaceDust__
  • 4,844
  • 4
  • 43
  • 82
  • 2
    Does this answer your question? [Preview throwing error in SwiftUI: ConfigurationError: noPreviewInfos](https://stackoverflow.com/questions/67343759/preview-throwing-error-in-swiftui-configurationerror-nopreviewinfos) – lorem ipsum Dec 26 '21 at 01:55
  • It didn't answer my question, why are you trying to vote to close the question? – SpaceDust__ Dec 26 '21 at 16:21
  • 3
    Needed either minimal reproducible example or access to project. – Asperi Dec 28 '21 at 18:46
  • 1
    This issue is primarily hardware-related. I had the same problem when a SwiftUI file wouldn't preview even though it would build and run fine. If I removed every view from the SwiftUI file (minimal preview), it worked. I kept on adding lines of code one by one, but it would crash after a set view complexity had been reached. The only hope you have is to switch to a better machine (hardware-wise) and use Xcode 12 rather than 13. – Asad Dec 31 '21 at 12:39
  • 1
    I had a similar issue. Not same error, but any project, old or new (Hello world), preview would fail, always. Repeated the ridiculous `xcodebuild -license accept` multiple times, nothing. Finally was able to reset by removing a PCM file, following: https://stackoverflow.com/a/70617215/3276518 – bauerMusic Feb 02 '22 at 07:21
  • @u.gen did you solve it? – Sonia Casas Jun 07 '22 at 14:23

2 Answers2

0

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.

Vera Gonzalez
  • 474
  • 2
  • 5
-4

Usually, this kind of issue gets resolved by clearing up the derived data folder. Below are the steps I usually follow:

  • Deep clean the project by using Cmd+Alt+Shft+K
  • Quit Xcode
  • Clear derived data folder
  • Restart Mac(Not required always)
  • Restart Xcode
shim
  • 9,289
  • 12
  • 69
  • 108