In the first Xcode 16 beta, none of my SwiftUI previews work - they all just crash on start up.
Has anybody run into this and found a workaround? Have tried all the usual steps of cleaning the project/restarting Xcode.
Xcode Previews
RSS for tagCreate an app UI and configure almost everything your users see using Xcode Previews.
Posts under Xcode Previews tag
160 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hey Guys, a have some problens with Xcode preview for some reason I'm getting this error
LinkDylibError: Failed to build CardDetailsScreen.swift
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: -make_mergeable can only be used when creating a dynamic library
clang: error: linker command failed with exit code 1 (use -v to see invocation)
previews_diagnostics_summary.txt
As someone who frequently uses Preview, it would be convenient to have the option to view the preview on another display. Are there any existing methods or plans to introduce a feature that allows us to pop out the previews to another screen?
Hey,
I've opened an existing project with Xcode 16 Beta 1 (I'm also running macOS Sequoia).
None of my previews work anymore. They simply crash with an error I don't quite understand:
JITError
==================================
| NoBuiltTargetDescriptionCouldBeFound
|
| translationUnit: PreviewTranslationUnit(moduleNamePrefix: "Previews_ErrorView", sourceIdentifier: file:///Users/dennis/Code/Project/Project/Components/ErrorView.swift -> ErrorView.swift, parseTree: ParseTree(version: 1848, statements: 5, providers: 0), update: nil, changesContextMemoizer: PreviewsPipeline.PreviewTranslationUnit.(unknown context at $3561fdc4c).ChangesContextMemoizer(parseTree: ParseTree(version: 1848, statements: 5, providers: 0), sourceIdentifier: file:///Users/dennis/Code/Project/Project/Components/ErrorView.swift -> ErrorView.swift, cachedValue: os.OSAllocatedUnfairLock<Swift.Optional<PreviewsModel.ParseTree.PreviewChangesContext>>(__lock: Swift.ManagedBuffer<Swift.Optional<PreviewsModel.ParseTree.PreviewChangesContext>, __C.os_unfair_lock_s>)), registryDeclarationMemoizer: PreviewsPipeline.PreviewTranslationUnit.(unknown context at $3561fdbec).RegistryDeclarationMemoizer)
|
| builtTargetDescriptions:
The app builds and runs fun on a simulator and on device.
Any ideas what this error means? Is this just an early Beta 1 bug or might there be anything I can do in my project to fix this?
The WWDC24 demo projects all work fine and their previews are working as well.
Thanks!
SwiftUI Previews that work in Xcode 15.2 now fail in Xcode 15.3 with failedToGenerateThunkInfo error
I have a Swift Package Manager module with some SwiftUI files that I was using Previews without issues in Xcode 15.2. When I upgraded to Xcode 15.3, it fails with “Cannot preview in this file. Unexpected error occurred”. When I click to get more info, this is the error:
== PREVIEW UPDATE ERROR:
HumanReadableSwiftError
BuildError: failedToGenerateThunkInfo(could not generate preview info: noTargetBuildGraph)
Is anyone experiencing the same problems? My preview, which lives in a SPM package, works totally fine in Xcode 15.2, but fails in Xcode 15.3. Any ideas for how to fix it? I've tried deleting DerivedData, resetting package caches, clean building.
So frustrating seeing these regression issues popping up still.
I filed FB13678356 but it was quickly marked as "Investigation Complete - Unable to diagnose with current information" but there was no request for what further information I could provide! I attached a full sysdiagnose and error log!
Would also note, that when I revert back to Xcode 15.2, the previews go back to working...
Summary
When trying to display SwiftUI previews, building the previews may fail with the following error:
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found
ld: warning: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found
Note that may app does not use CoreAudioTypes.
Observation
This issue seems to occur when two conditions are met:
The SwiftUI view must be located in a Swift Package
Somewhere in either the View or the #Preview a type from another package has to be used.
Say I have to packages one named Model-package and one named UI-Package. The UI-Package depends on the Model-Package. If I have a SwiftUI view in the UI-Package that uses a type of the Model-Package either in the View itself or in the #Preview, then the described error occurs. If I have a View in the UI-package that does not use a type of the Model-Package anywhere in its View or #Preview then the SwiftUI Preview builds and renders successful.
I created a bug report: FB13033812
Hello,
In WidgetKit, I have to write multiple #Preview macros for each family the widget supports. So is there any better way to write the #Preview?
(Although I can use the legacy PreviewProvider but it does not support timeline to test transition animation.)
#import WidgetKit
#import SwiftUI
struct DailyCaffeineWidget: Widget {
...
}
@available(iOS 17.0, *)
#Preview("Inline", as: .accessoryInline) {
DailyCaffeineWidget()
} timelineProvider: {
previewTimelineProvider()
}
@available(iOS 17.0, *)
#Preview("Circular", as: .accessoryCircular) {
DailyCaffeineWidget()
} timelineProvider: {
previewTimelineProvider()
}
@available(iOS 17.0, *)
#Preview("Rectangular", as: .accessoryRectangular) {
DailyCaffeineWidget()
} timelineProvider: {
previewTimelineProvider()
}
@available(iOS 17.0, *)
#Preview("Small", as: .systemSmall) {
DailyCaffeineWidget()
} timelineProvider: {
previewTimelineProvider()
}
@available(iOS 17.0, *)
#Preview("Medium", as: .systemMedium) {
DailyCaffeineWidget()
} timelineProvider: {
previewTimelineProvider()
}
...
On May 1 I started to see this image instead of watch UI preview. It worked well before. I didn't update Xcode, neither I deleted or installed any new simulator OS. It was harmful to my work, since simulator download is 4GB and I need to wait when it downloads, instead of reviewing PRs and closing tasks.
Did anyone had the same issue? Do you know how to prevent it?
#Preview, @available(iOS 17, *), PreviewProvider
Preview is not working.
I've tried this and that, but I can't.
Please help me.
I already filed feedback FB13777941 for this, but wanted to ask if anyone has the same problem, since I can't find anything on google or SO.
I created a new package in Xcode (15.3) and added this to it:
import SwiftUI
struct Test: View {
var body: some View {
Text("Hello world")
}
}
#Preview {
Test()
}
The package builds, tests can run. Previews don't work.
This is more or less the error I get from the diagnostics button (formatted for readability):
LoadingError: failed to load library at path ”PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct”: Optional(dlopen(PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct, 0x0000):
tried:
'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file),
'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')),
'/System/Volumes/Preboot/Cryptexes/OSPATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file),
'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')),
'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file),
'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')),
'/System/Volumes/Preboot/Cryptexes/OSPATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file),
'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')))
I don't remember ever having this problem. The arm64 vs arm64e makes no sense to me - why would Xcode get that wrong... and only for previews?
I've tried restarting, deleting derived data, the usual rain dances.
Any ideas?
Starting on Xcode 15.3 and 15.4 my SwiftUI Previews stopped working with the following error:
== PREVIEW UPDATE ERROR:
LinkDylibError: Failed to build ContentView.swift
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found
Undefined symbols for architecture arm64:
"static MyLibrary.DisplayUtil.getText() -> Swift.String", referenced from:
closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o
"type metadata accessor for MyLibrary.DisplayUtil", referenced from:
closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
After much trial and error, I narrowed it down to my SwiftUI views using properties or functions inside components in Swift Packages.
This is a simple example of my Swift Package:
public class DisplayUtil {
public func getText() -> String {
return "Text"
}
public static func getText() -> String {
return "Text"
}
}
And my SwiftUI View
import SwiftUI
import MyLibrary
struct ContentView: View {
var body: some View {
VStack {
Text(DisplayUtil.getText())
}
.padding()
}
}
#Preview {
ContentView()
}
The same code works fine on Xcode 15.2
Link to the sample project:
https://www.icloud.com/iclouddrive/0c00AD0esi2PwqqiRggokfwGw#Demo%5FBroken%5FPreview
Is anybody else having a similar issue?
Can anyone give me assistance on how to fix this. My preview crashed because a Fatal Error in ModelData.
This is how my ModelData looks:
import SwiftUI
struct SutraokeDetail: View {
@Environment(ModelData.self) var modelData
var sutra: Sutras
var body: some View {
@Bindable var modelData = modelData
ScrollView {
CircleImage(image: sutra.image)
.offset(y: -130)
.padding(.bottom, -130)
VStack(alignment: .leading) {
HStack{
Text(sutra.name)
.font(.title)
Spacer()
Text(sutra.text)
}
}
}
}
}
#Preview {
let modelData = ModelData()
return SutraokeDetail(sutra: modelData.sutras[0])
.environment(modelData)
}
Hello,
I use Preview to quickly test functionalities. However I found that the unified logging does not output to Preview console. So I had to do both log.debug and print. Is there a way to enable logging to Preview console?
Hello. I've been looking all over this forum and stack and done some internet searches but unfortunately have found nothing to assist in fixing an error I'm receiving on my project in Xcode.
Every view shows an error identical to the one shown above, only with that specific file name displayed instead. When I go to fix the error, this is the error detail displayed:
== PREVIEW UPDATE ERROR:
LinkDylibError: Failed to build TabBar.swift
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found
ld: unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '/Users/brycemchose/Library/Developer/Xcode/DerivedData/Service_Square_App-dnblqgabcrxprhaizjtkcvouyzln/Build/Intermediates.noindex/Previews/iphonesimulator/Service Square App/Products/Debug-iphonesimulator/Service Square.app/Service Square'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Note that I can run the app successfully to a simulator or to my iPhone, but cannot see the preview within the Xcode canvas. I've been blindly developing the last two app updates, pushing the changes to the simulator and then tweaking the code based on the simulated version. I can keep doing this for a little while but it is significantly slower and more difficult, especially to fix small bugs and make tiny changes, so I'd really like to see if anyone has an idea for how I can get the preview back to being properly displayed. I'm brand new to this whole thing and have no idea how to fix this issue, so I'd be really grateful if someone with more experience could offer some suggestions! Thanks in advance! :)
I'm seeing some weird behavior with conditional compilation when I use a build configuration other than "Debug" or "Release", and I'm wondering if I'm doing something wrong or if this is an Xcode bug.
The setup
Xcode version: 15.3
I have a simple SwiftUI view that takes in a model and displays an attribute of the model.
struct ContentView: View {
let model: Model
var body: some View {
VStack {
Text("Name: \(model.name)")
}
.padding()
}
}
In the model file, I have the struct definition, but also an extension that defines some sample data for use in SwiftUI previews:
struct Model {
let id: String
let name: String
}
#if DEBUG
extension Model {
static let example = Model(
id: "50fef362-f53d-4ded-9168-b887ff62e59d",
name: "John Doe"
)
}
#endif
And finally, I have a preview provider that uses this sample data:
#Preview {
ContentView(model: Model.example)
}
Normal behavior
With the default "Debug" build configuration, this works just fine. There are no compilation errors, and the preview renders as expected.
The issue
Start off by changing the name of the build configuration to, e.g. "DebugDev"
Now I start seeing seeing a mis-match between what happens and what Xcode tells me is happening.
The code still compiles and runs, and the SwiftUI preview still works, but Xcode is displaying things as if it doesn't compile.
Xcode formats the conditionally compiled code with a lower opacity color as if DEBUG isn't defined:
In the view file, I now see a compilation error when referencing the conditionally-compiled code:
Autocomplete doesn't work when trying to reference the conditionally compiled code
Additional details/observations
I have confirmed that the DEBUG active compilation condition is still defined in the build settings. All I've done is change the name of the build config
I was initially thinking this might have something to do with the fact that this appears in a preview provider, since those are treated a bit differently, but the same thing happens if I reference the conditionally compiled code directly in the view class
Another theory: since I was referencing conditionally compiled code from code that wasn't conditionally compiled, maybe Xcode was trying to tell me that wasn't valid. So, I tried placing the code that calls the conditionally compiled code (in this case, the view class) inside an #if DEBUG. This does get rid of the displayed compilation error, but auto-complete still doesn't work, and the whole class is displayed with the lower-opacity font.
Help?
I feel like I must be missing something. The only alternative I can think of is that Xcode has some logic hard-coded with the default "Debug" build config, and that would be...just silly.
With the newest version of Xcode (15.3) I cannot get Preview to load and am getting the following error:
HumanReadableSwiftError
CancellationError: CancellationError()
I'd had this same issue a few months ago and opening up an older project's previews and then opening the project I was working on would allow Preview to show.
The last few weeks I've not been getting this error and after 3 or 4 days not being in Xcode I'm getting this same error again.
I'm relatively new to Xcode and Swift so not being able to load the darn preview and work through tutorials after seemingly doing the exact same thing I've been doing for months is quite ridiculous and frustrating.
Any ideas on how to resolve this issue would be greatly appreciated.
So like the title says, when I start up Xcode the preview won;t work till I run a debug session using the simulator.
Sometimes the debug session is unable to start the simulator, which I can start manually then run a debug session.
Once all the above is done, preview works.
Any idea what is causing this behavior?
SwiftUI Preview Don't work.
Progress Preparing iPhone Simulator for Previews.
SwiftUI
Xcode version 13.0
macOS Big Sur version 11.6
The Build for Previews builds all my targets including the test targets. Is there a way to configure the relevant targets? I do not see an option in the schema editor, and disabling Find Implicit Dependencies has no effect either.
Hi All,
I have been using Xcode for less than 5 months.
Recently I get a problem that my previews does not load, even when I created a new project on a local disk.
The Project builds, but the preview does not.
The error I saw from the Diagnostics window is as below
== PREVIEW UPDATE ERROR:
HumanReadableSwiftError
CancellationError: CancellationError()