Xcode Previews

RSS for tag

Create an app UI and configure almost everything your users see using Xcode Previews.

Posts under Xcode Previews tag

76 Posts

Post

Replies

Boosts

Views

Created

Gathering Required Information for Troubleshooting Xcode Previews or Swift Previews Issues
Hi, You're here because your project has issues related to Xcode Previews or Swift Previews. The issue you're experiencing may be the result of any of the following: An error in your SwiftUI app, Xcode previews, or on-device previews. A configuration error in your Xcode project, including any third-party dependencies or packages. A system issue in the operating system, SwiftUI, or in Xcode Previews. Based on your request, I need more information about your SwiftUI app when rendering Xcode Previews or on-device previews. Specifically, I’ll need the diagnostics Swift Previews generates to make sure I understand the error encountered by the preview system. Please create a report in Feedback Assistant to share the details requested in the instructions below. For issues with macOS, Mac Catalyst, on-device iOS, or on-device visionOS previews, perform the following steps to gather diagnostics: Download and install the Swift Previews logging profile for your device. Reproduce the error while previewing on device, taking note of the timestamp when the error occurred. Attach the Previews diagnostics, sysdiagnose from your Mac, a sysdiagnose from the previewing iOS or visionOS device. For issues with Xcode Previews, perform the following steps to gather diagnostics: Download and install the Swift Previews logging profile for your device. Reproduce the error in Xcode Previews, if you haven’t already done so. If an error banner appears in the canvas, click the "Diagnostics" button within the banner, then go to Step 5; otherwise, continue to Step 4. If the error banner is missing, navigate to the menu in Xcode: Editor > Canvas > Diagnostics In the presented sheet, click the "Generate Report" button. Attach a zip file containing the diagnostic report to your bug report (it will be named something like previews-diagnostics-0123456789.zip). Submitting your feedback Before you submit to Feedback Assistant, please confirm the following information is included in your feedback: with the Swift Previews logging profile installed, attach the sysdiagnose logs gathered after reproducing the issue the Previews diagnostics generated by Xcode timestamp identifying when the issue was reproduced focused sample Xcode project that reproduces the issue (if applicable) screenshots or videos of the error (optional) Please include all requested information to prevent delays in my investigation. After your submission to Feedback Assistant is complete, please respond to your original Forums post with the Feedback ID. Once received, I can begin my investigation and determine if this issue is caused by an error within your SwiftUI app, a configuration issue within your Xcode project, or an underlying issue in the operating system, SwiftUI, in Xcode Previews, or on-device previews. Cheers, Paris X Pinkney |  WWDR | DTS Engineer
0
0
393
Feb ’25
XCPreviewAgent crashes with KERN_PROTECTION_FAILURE on macOS 26.0.1 Tahoe
Hello, I'm experiencing consistent crashes of XCPreviewAgent when using Xcode Previews on macOS 26.0.1 Tahoe (25A362). Configuration: macOS: 26.0.1 (25A362) - stable release Xcode: 16.0 (23.0.54) - stable release Hardware: MacBook Pro M4 Project: SwiftUI iOS app Issue: Every time I try to use Xcode Previews, XCPreviewAgent crashes with: Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Subtype: KERN_PROTECTION_FAILURE at 0x0000000340e54000 Termination Reason: Namespace SIGNAL, Code 10, Bus error: 10 The crash occurs in shared memory region during dynamic library loading. What I've tried: Cleared all caches: rm -rf ~/Library/Developer/Xcode/DerivedData Deleted Preview data: rm -rf ~/Library/Developer/Xcode/UserData/Previews Reset simulators: xcrun simctl --set previews delete all Switched xcode-select to /Applications/Xcode.app/Contents/Developer Tried both Xcode stable and Xcode beta Created fresh simulators Clean build (Cmd+Shift+K) Rebooted Mac multiple times The app runs fine on simulator (Cmd+R), but Previews consistently crash.
1
0
55
3d
SwiftUI macOS Preview Crash When Using Custom Row Directly Inside List
I’ve hit a strange SwiftUI preview crash that happens on macOS previews when using a view inside a List’s ForEach, resulting in the error Fatal Error in TableViewListCore_Mac2.swift. Only crashes macOS preview - iPhone/iPad preview doesn't crash. Doesn't crash when actually running the app. Here’s a minimal reproducible example, causing the preview to crash. XCode: Version 26.0.1 (17A400) MacOS: 26.0.1 (25A362) import SwiftUI struct Item: Identifiable { let id = UUID() let name: String } struct ItemRow: View { let item: Item var body: some View { HStack { Button(action: {}) { Image(systemName: "play") } Text(item.name) Spacer() ProgressView() } } } struct ContentView: View { @State private var items = [ Item(name: "Item A"), Item(name: "Item B"), ] var body: some View { List { ForEach(items) { item in ItemRow(item: item) } } } } #Preview("Content view") { ContentView() } #Preview("Item row") { ItemRow(item: Item(name: "Item A")) } If I wrap the row in a container, like this: ForEach(items) { item in ZStack { ItemRow(item: item) } } the crash seems to disappear. Has anyone else seen this behavior? What might I be doing wrong? Any ideas about what could be causing this?
1
0
70
3w
Xcode forces my Macbook to restart when previewing canvas
I can't use Xcode without it crashing. Just writing a very simple iOS app with SwiftUI (using only forms and sections). Whenever my canvas updates to correspond to my changes it forces my Macbook to restart. Does anyone have a solution for this. I'll be honest it's becoming really frustrating. Thank you. Macbook M3 Pro 16GB ram, 500gb Space (400gb free space)
1
0
73
Aug ’25
Xcode restarts my Macbook when previewing canvas
I have an issue with Xcode that it crashes my Macbook and restarts it instantly when I unpause the preview canvas. I managed to make it run for a minute longer by not watching a youtube video. I am writing a very simple SwiftUI project for iOS nothing too big to warrant any issues. Does anyone have a solution to fix this? Macbook Pro M3 16GB RAM, 500GB SSD (plenty of storage space) Tahoe 26.0
1
0
74
Aug ’25
Using Previews causes a system crash on Xcode 26 Beta 4 and MacOS 26 Beta 4
Hey, I've updated to both Xcode 26 Beta 4 and MacOS 26 Beta 4. Both run super stable so far. However, every time I use Xcode Previews for a few minutes, the entire system freezes for a few seconds and then crashes and reboots. I'm trying to generate a system diagnosis (which it offers me after the reboot), but it seems to be stuck generating. It's hard to say what exactly causes the crash, unfortunately. But it happened multiple times after starting to use Xcode Previews. Anyone else has that problem? I've also filed a feedback for this: FB19013059 Cheers Dennis
11
12
657
Jul ’25
Preview crashes when using ForEach with a Binding to an array and generics
The following repro case results in a previews crash on Xcode 26 beta 3 (report attached). FB18762054 import SwiftUI final class MyItem: Identifiable, Labelled { var label: String init(_ label: String) { self.label = label } } protocol Labelled { var label: String { get } } struct HelloView: View { let label: String var body: some View { Text(label) } } struct ListView<Element: Labelled & Identifiable>: View { @Binding var elements: [Element] var body: some View { List { ForEach($elements, id: \.id) { $element in HelloView(label: element.label) // crash // Replacing the above with a predefined view works correctly // Text(element.label) } } } } struct ForEachBindingRepro: View { @State var elements: [MyItem] = [ MyItem("hello"), MyItem("world"), ] var body: some View { ListView(elements: $elements) } } #Preview("ForEachBindingRepro") { ForEachBindingRepro() } foreachbindingrepro-2025-07-12-020628.ips
6
0
189
Jul ’25
Using @Environment for a router implementation...
Been messing with this for a while... And cannot figure things out... Have a basic router implemented... import Foundation import SwiftUI enum Route: Hashable { case profile(userID: String) case settings case someList case detail(id: String) } @Observable class Router { var path = NavigationPath() private var destinations: [Route] = [] var currentDestination: Route? { destinations.last } var navigationHistory: [Route] { destinations } func navigate(to destination: Route) { destinations.append(destination) path.append(destination) } } And have gotten this to work with very basic views as below... import SwiftUI struct ContentView: View { @State private var router = Router() var body: some View { NavigationStack(path: $router.path) { VStack { Button("Go to Profile") { router.navigate(to: .profile(userID: "user123")) } Button("Go to Settings") { router.navigate(to: .settings) } Button("Go to Listings") { router.navigate(to: .someList) } .navigationDestination(for: Route.self) { destination in destinationView(for: destination) } } } .environment(router) } @ViewBuilder private func destinationView(for destination: Route) -&gt; some View { switch destination { case .profile(let userID): ProfileView(userID: userID) case .settings: SettingsView() case .someList: SomeListofItemsView() case .detail(id: let id): ItemDetailView(id: id) } } } #Preview { ContentView() } I then have other views named ProfileView, SettingsView, SomeListofItemsView, and ItemDetailView.... Navigation works AWESOME from ContentView. Expanding this to SomeListofItemsView works as well... Allowing navigation to ItemDetailView, with one problem... I cannot figure out how to inject the Canvas with a router instance from the environment, so it will preview properly... (No idea if I said this correctly, but hopefully you know what I mean) import SwiftUI struct SomeListofItemsView: View { @Environment(Router.self) private var router var body: some View { VStack { Text("Some List of Items View") Button("Go to Item Details") { router.navigate(to: .detail(id: "Test Item from List")) } } } } //#Preview { // SomeListofItemsView() //} As you can see, the Preview is commented out. I know I need some sort of ".environment" added somewhere, but am hitting a wall on figuring out exactly how to do this. Everything works great starting from contentview (with the canvas)... previewing every screen you navigate to and such, but you cannot preview the List view directly. I am using this in a few other programs, but just getting frustrated not having the Canvas available to me to fine tune things... Especially when using navigation on almost all views... Any help would be appreciated.
2
0
263
Jul ’25
XCPreviewAgent crashed with some SwiftUI View
The steps to reproduce this issue are a bit complicated. In my app, previewing View A in Package P works fine, but another view in the same package fails to preview. The error message is shown below. It seems that the memory used for the preview is interfering with the shared memory area. This is reported as FB18519266 Exception Subtype: KERN_PROTECTION_FAILURE at 0x00000003402d8900 Exception Codes: 0x0000000000000002, 0x00000003402d8900 VM Region Info: 0x3402d8900 is in 0x3402c8000-0x340a18000; bytes after start: 67840 bytes before end: 7599871 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL mapped file 3401dc000-3402c8000 [ 944K] r-x/rwx SM=COW Object_id=57e4ac ---> shared memory 3402c8000-340a18000 [ 7488K] rw-/rw- SM=SHM mapped file 340a18000-340f38000 [ 5248K] r-x/rwx SM=COW Object_id=1dc9a049 Termination Reason: ****** 10 Bus error: 10 Terminating Process: exc handler [94787]
3
0
137
Jul ’25
Xcode Vorschau funktioniert nicht
Hallo ich bin neu auf dem gebiet IOS Apps zu coden und habe mit Xcode heruntergeladen aber bin direkt am verzweifeln die Live Vorschau lädt bei mir nicht direkt von Anfang an nachdem ich das Projekt erstellt habe. Ich hab schon etliche Sachen versucht ich habe Xcode komplett neu installiert genauso wie den Ordner neu bauen lassen usw. Jetzt seit ihr meine letzte Hoffnung hatte jemand auch schonmal das Problem und kann mir dabei helfen!
1
0
91
Jun ’25
SwiftUI #Previews: How to populate with data
Suppose you have a view: struct Library: View { @State var books = [] var body: some View { VStack { ... Button("add Book") { .... } } } Such that Library view holds a Book array that gets populated internally via a button that opens a modal – or something alike. How can I use #Peviews to preview Library with a pre-populated collection? Suppose I have a static books – dummy – array in my code just for that; still, what's the best way to use that to preview the Library view?
4
0
91
Jun ’25
Widget Previews in visionOS 26 Beta (Xcode 26 Beta)
Hello, I'm currently developing for visionOS using Xcode's latest beta version. I have a question regarding Widget Previews for visionOS 26: When I create a new Widget Extension target directly from a visionOS project, the generated code does not include the #Preview macro. Following the documentation, I manually added the #Preview macro to a Widget created within a visionOS project, but Xcode then displays an error stating that "This platform does not support previewing widgets." My interpretation is that Widget Previews are currently not supported for Widgets created specifically for visionOS in this beta version. Is this understanding correct? Or am I missing a specific way to implement previews for visionOS Widgets, or is there a particular project setting I might have overlooked? Any clarification or guidance on this matter would be greatly appreciated. Thank you.
1
0
119
Jun ’25
Xcode #Playground fails
I'm watching the session video "What's new in Xcode 26" and when I try out the new #Playground macro (in the context of a local package in my project) I see only this activity indicator for about 10-15 minutes: Eventually I do see this error: Despite the error, my local package does not import SwiftUI and has no dependencies other than Foundation. I checked the Xcode 26 release notes and I don't see this issue mentioned. A clean build of my project takes 55 seconds. Is it expected behavior that #Playground would require 10+ minutes to spin up? Is there anything I can to do make the new #Playground macro work correctly? Thank you.
2
0
152
Jun ’25
Could not find library with name ”/usr/lib/swift/libswiftWebKit.dylib“
Canvas Previews (targeting macOS) in both Xcode 16.4 & Xcode 26 fail to load, when the project imports a Swift package that imports and uses WebKit. I'm on macOS 15.5. Tried also to bring minimum targets of both the project and the package to 15.0. I see that there are some work-arounds for iOS simulator but nothing for the Mac. Anyone facing the same problem?
5
0
187
Jun ’25
Xcode Preview & Simulator test failed
I upgraded IOS to 15.5 yesterday and then my xcode failed to preview today. The error message I got is: Communication with Apple failed Your team has no devices from which to generate a provisioning profile. Connect a device to use or manually add device IDs in Certificates, Identifiers & Profiles. https://developer.apple.com/account/ Any one knows how to fix it?
0
0
95
Jun ’25
Why is Xcode so slow and bad?
I just want to rant why is Xcode such a bad ide and I wish Apple can do a better job on Xcode. Here's why: The preview is so slow. Most of the times it's just faster for me to test on a real device. It is so slow, and many times I need to force quite after it's being unresponsive for sometimes. When I'm working on larger projects, the loading time becomes extremely slow especially when there's other clients that might be reading the same files like a Git client or simply iCloud. The breakpoint is so slow. I don't know why, is it an iOS thing? But when I'm on ASP.Net the breakpoints are super fast. For Xcode it takes a long time to pause and show data. It's so big I don't know why it is so hard for Apple to make their ide better. The community has been unsatisfied with Xcode for a long time. There's many tricks on the internet that you can find to help you resolve some issues with your project that's actually related to Xcode. Instead of using these tricks, Apple should just fix these issues. Learn from Intellij!
1
3
227
May ’25
Xcode Resets the Canvas (Preview) Window
Hello, In the recent update i installed of Mac and Xcode. After working out the initial problem of Simulator runtimes not found, I created a new project with new problem where When i switch to a different file, or Hide and Show Canvas again it just resets to its size (approx. 50%) of Editor. The current solution is to Pin it and it stays there with right size (No matter which file - with any extension - to switch from or to then). I tried deleting Derived Data folder, Rebooting Mac, Reintsalled Xcode (When Simulator Runtime not found problem) but the problem is there. I also tried trait property but fixedLayout do not work with iOS.
1
0
101
May ’25
Canvas keeps resizing to 50/50 width in Xcode
Hello, Xcode seems to reset the canvas preview every time I open a file that does not have a preview. This is extremely annoying when working with two editor tabs. The resize happened before only after restarting Xcode since a few weeks it happens always when opening another file. The preview phone does not even take advantage of the resize. Is there a way to fix this? When I work with the file: After opening a file without preview and going back:
1
0
114
May ’25
Previews globally fail with CouldNotLoadInputObjectFile error
Whenever I try to use SwiftUI previews, the preview fails with a CouldNotLoadInputObjectFile error like this: == PREVIEW UPDATE ERROR: FailedToLaunchAppError: Failed to launch com.my-company.Test | ================================== | | [Remote] CouldNotLoadInputObjectFile: Could not load object file during preview: /Users/me/Library/Developer/Xcode/DerivedData/Test-dzmdthicvcbuwkawncuacsomcdcd/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/TestApp.o | | | | path: /Users/me/Library/Developer/Xcode/DerivedData/Test-dzmdthicvcbuwkawncuacsomcdcd/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/TestApp.o | | | | ================================== | | | [Remote] XOJITError | | | | | | XOJITError: '/Users/me/Library/Developer/Xcode/DerivedData/Test-dzmdthicvcbuwkawncuacsomcdcd/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/TestApp.o': No such file or directory It appears that the preview process cannot find the compiled .o files. However, when I check in Finder, the files do exist and normally running the app works fine. It is noteworthy that this is independent of the XCode project or view I try to preview. It is a global issue on my system. Previews not even work when I create a blank new SwiftUI project in XCode. I tried deleting all caches, derived data, preview caches etc. But without any effect. I have this in XCode 16.3 as well as in 16.4 RC. On macOS Sequoia 15.4.1 on a MacBook Air M4. Does anybody have an idea what might be causing this?
3
2
130
May ’25
SwitUI preview loads indefinitely
Hi! I develop an iOS library and I met an issue with SwiftUI previews in iOS app project with my library integrated. After I open preview, build for preview finishes successfully, but preview itself never appears. I failed to find any error messages or any other indicators of what went wrong or how to fix it. Switching to legacy preview execution seems to fix problem, but I think that is not ideal. Could you help fixing this? Xcode 16.2, Simulator iPhone 16, iOS 18.2 Project to reproduce - https://drive.google.com/file/d/1cU6JKwshK_wQfe9YIqcMg3UGWq45OYlx/view?usp=sharing Preview diagnostics - https://drive.google.com/file/d/1kPcgVSSqreiepGuqhdIoCW2rLSicgsWr/view?usp=sharing
7
0
208
May ’25