Swift UI previews in modular app with frameworks
Asked Answered
T

2

7

Having an issue running the preview for SwiftUI views inside my framework. Here is a project structure.enter image description here

Preview for SwiftUI views that are in the main target ( ContentView, GradientView) work as expected.

However, when I’m trying to preview the view inside UI.xcodeproject ( SwiftUIView) I’m getting an error

enter image description here

PotentialCrashError: Update failed

XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.

==================================

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path "/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib": Optional(dlopen(/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib, 0x0002): tried: '/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Products/Debug-iphonesimulator/SwiftUIView.1.preview-thunk.dylib' (errno=2), '/Applications/Xcode_14.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib' (errno=2), '/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')))
|  
|  ==================================
|  
|  |  MessageSendFailure: Message send failure for <ServiceMessage 115: update>

~/Library/Logs/DiagnosticReports folder is empty.

Using Xcode 14.0 in Rosetta mode.

Xcode 14.1 in Rosetta mode - same issue

Ths same configuration without Rosetta works fine. (in my prod project I have to use Rosetta because of 3rd party dependency)

Build for Active architecture set to NO

Build for Active architecture set to YES changes nothing

All the usual things tried:

  • Rebuild project
  • Clean Derived Data
  • Etc.
The answer to those who came here with the same problem: 

If you have to run in **Rosetta** mode, keep checking this post.

Otherwise, run without **Rosetta**, that will solve your problem.
Tanked answered 3/11, 2022 at 18:11 Comment(1)
First, try building your project - this might regenerate the DerivedData. Try cleaning your Xcode build folder and restarting Xcode. Note: Xcode SwiftUI previews tend to be notoriously finicky. If this does not work, try deleting DerivedData. Also note that Xcode previews will not work if you have any compile errors.Heartrending
L
0

I'm hitting this same issue. Building on an M1Pro, rosetta not installed. iOS project. Previews were working then stopped the other day after I moved some code around to fit within the desired app structure (not mine). The preview error indicates one particular swift source file but when I copied that to another project it compiled and previewed perfectly.

Lonesome answered 22/2, 2023 at 5:4 Comment(0)
G
0

I am able to solve this by uncheck open using Rosetta option.

enter image description here

Goodsell answered 29/11, 2023 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.