Eugene P
Eugene P

Reputation: 572

Swift UI previews in modular app with frameworks

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:

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.

Upvotes: 7

Views: 1448

Answers (2)

Pawan Kumar
Pawan Kumar

Reputation: 558

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

enter image description here

Upvotes: 0

drekka
drekka

Reputation: 21883

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.

Upvotes: 0

Related Questions