Xcode Previews

RSS for tag

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

Xcode Previews Documentation

Posts under Xcode Previews tag

161 Posts
Sort by:
Post not yet marked as solved
0 Replies
336 Views
The preview or editor canvas is not working in my xcode app. I have updated my computer, updated the app, deleted and reinstalled the app, done cmd+shift+k, turned off automatically refresh canvas, tried previewing it on an older model iphone, but havent found a solution. Message me for my feedback id and disagnostic report, because it is not leeting me add it without being flagged for sensitive content
Posted Last updated
.
Post not yet marked as solved
2 Replies
1k Views
I'm trying to preview a SwiftUI view that resides in a local Swift package. I have the Swift package selected as the current scheme, so all the proper dependencies are available and the build succeeds. But I see this message in the Preview window: Cannot show preview: check whether the preview is compiled for the current scheme and OS of the device used for previewing How do I ensure the preview is compiled for a particular scheme and device OS? I updated MacOS to 14.3.1 and Xcode to 15.3 in the hopes that that might fix this issue, but it did not.
Posted Last updated
.
Post marked as solved
4 Replies
416 Views
Building in visionOS and one of my Swift UI views keeps causing Xcode to crash. The root issue is within the preview code, stuck on updating the preview code to prevent Xcode from crashing. When I run the simulator the app works perfectly, no bugs or issues. Any advice on how to update the preview code would be very helpful :) import RealityKit import RealityKitContent struct BrandImage: View { @State private var currentIndex: Int = 0 @Environment(\.openWindow) private var openWindow @EnvironmentObject var sharedAppState: SharedAppState var brand: [BrandEcommData] var initialBrand: BrandEcommData init(brand: [BrandEcommData], initialBrand: BrandEcommData) { self.brand = brand self.initialBrand = initialBrand if let initialIndex = brand.firstIndex(where: { $0.id == initialBrand.id}) { _currentIndex = State(initialValue: initialIndex) } } var body: some View { HStack(spacing: 0) { ZStack { ForEach(0..<brand.count, id: \.self) { index in if index == currentIndex { VStack { Text(brand[index].brand) .padding(.top, 5) brand[index].image .resizable() .scaledToFit() } .transition(.scale) } } HStack { Button(action: { withAnimation { self.currentIndex = (self.currentIndex - 1 + brand.count) % brand.count sharedAppState.currentModelId = brand[currentIndex].id } }) { Image(systemName: "arrow.left.circle.fill") .font(.largeTitle) .foregroundStyle(.linearGradient( colors: [.black, .gray], startPoint: .top, endPoint: .bottom)) } .padding(.leading, 20) Spacer() Button(action: { withAnimation { self.currentIndex = (self.currentIndex + 1) % brand.count sharedAppState.currentModelId = brand[currentIndex].id } }) { Image(systemName: "arrow.right.circle.fill") .font(.largeTitle) .foregroundStyle(.linearGradient( colors: [.black, .gray], startPoint: .top, endPoint: .bottom)) } .padding(.trailing, 20) } VStack { HStack { Spacer() Button(action: { openWindow(id: "volumetric") }) { Image(systemName: "cube.transparent") .font(.title) .padding() .foregroundStyle(.linearGradient( colors: [.black, .gray], startPoint: .top, endPoint: .bottom)) } } Spacer() } } .frame(maxWidth: .infinity) Rectangle() .frame(width: 2) .foregroundStyle(.linearGradient( colors: [.black, .gray], startPoint: .top, endPoint: .bottom)) VStack { Text(brand[currentIndex].name) .font(.title2) Text(brand[currentIndex].itemDetail) .font(.subheadline) Text(brand[currentIndex].itemDescription) .padding() Text(brand[currentIndex].price) } } .onAppear { sharedAppState.currentModelId = initialBrand.id } } } #Preview { if let initialBrand = ecommdata?.first { BrandImage(brand: ecommdata!, initialBrand: initialBrand) } else { Text("Unable to load 3D Asset") } }
Posted Last updated
.
Post not yet marked as solved
1 Replies
242 Views
I am working on a 2018 Macbook Air. Here is the diagnostic that is generated. previews_diagnostics_summary.txt
Posted
by ilyba.
Last updated
.
Post not yet marked as solved
2 Replies
479 Views
Anyone else having issues in Xcode preview where when you tap on a button to open a volume window nothing appears in the Xcode preview window? For example, if you download the Hello World Xcode project and try to open the globe volume after tapping the toggle button, the globe volume window never opens. Running the latest version of Xcode 15.3 beta.
Posted Last updated
.
Post not yet marked as solved
3 Replies
364 Views
I'm new to Xcode, and I'm learning using the apple swiftUI tutorial: https://developer.apple.com/tutorials/swiftui/creating-and-combining-views I did the first few steps, but I can't get the simulator preview to work. My mac and Xcode are updated, but I can't it to load. Everything works fine when I do a mac project. Thanks in advance.
Posted
by ncote.
Last updated
.
Post marked as solved
1 Replies
335 Views
Does an 'archive build' require 'preview content'? I've put swift source files into 'Preview Content' directories - one directory for the top-level App and one for an embedded framework. An 'archive build' fails, complaining about the code in a #Preview block. #Preview { // the archive build fails to find this `default` ?? let controller = PersistenceControllerTopLevelPreview.default let user = controller.user ... The framework has its 'Preview Context' specified in the Development Assets; same with the top-level App.
Posted
by GoZoner.
Last updated
.
Post not yet marked as solved
1 Replies
503 Views
Is the preview set to read-only mode in Xcode 15? Drag and drop of any library items to preview canvas doesn't work. Is this feature removed in Xcode 15? (I don't want to believe that it was so helpful)
Posted
by alexey3m.
Last updated
.
Post not yet marked as solved
8 Replies
2.3k Views
SwiftUI preview hangs on "Preparing iPhone Simulator for Previews". Also simulator hangs when trying to build and run. This occurred after I installed iOS 17 simulator. I tried reverting back to an iOS 16 version of the simulator, but haven't figured out how to do that. Build and run to an iPhone device works fine. Any ideas would be appreciated. Thanks.
Posted
by dekyte.
Last updated
.
Post not yet marked as solved
3 Replies
425 Views
Hello, I am a UIKit developer and I would like to try out SwiftUI. Unfortunately, my previews don't load. My situation is like the one described in this blog post: https://forums.developer.apple.com/forums/thread/704036. Unfortunately I can't update Xcode like that developer did. What I've tried: quitting and restarting Xcode, restarting my computer, resetting the simulator, deleting the derived data folder, creating new projects without storage options, test bundles or source control, editing the content view of the initial Hello World file. To be clear, I've just started learning about SwiftUI, just yesterday evening, and the previews have never loaded. Is the problem solvable? If so, how?
Posted
by Filippo02.
Last updated
.
Post not yet marked as solved
0 Replies
331 Views
I've setup a NavigationLink so users can tap on the image and they're taken to another view, in this case "FenderExperience". I can't for the life of me figure out how to make this oval bar behind the image disappear. Is this an Xcode preview issue? I'm running Xcode 15.2 struct BrandImage: View { var body: some View { VStack(alignment: .leading) { NavigationStack { Text("Ralph Lauren") .font(.title) .padding(.bottom, -5) Image("RL") .resizable() .scaledToFit() .frame(width: 300, height: 200) .overlay( RoundedRectangle(cornerRadius: 0) .stroke(Color.white, lineWidth: 2)) Text("Fender") .font(.title) .padding(.bottom, -5) NavigationLink(destination: FenderXperience()) { Image("Fender II") .resizable() .scaledToFit() .frame(width: 300, height: 95) .overlay( RoundedRectangle(cornerRadius: 0) .stroke(Color.white, lineWidth: 2)) } Text("Burton") .font(.title) .padding(.bottom, -5) Image("Burton") .resizable() .scaledToFit() .frame(width: 300, height: 200) .overlay( RoundedRectangle(cornerRadius: 0) .stroke(Color.white, lineWidth: 2)) Text("Ray Ban") .font(.title) .padding(.bottom, -5) Image("Ray Ban") .resizable() .scaledToFit() .frame(width: 300, height: 200) .overlay( RoundedRectangle(cornerRadius: 0) .stroke(Color.white, lineWidth: 2)) Text("Levi's") .font(.title) .padding(.bottom, -5) Image("Levis II") .resizable() .scaledToFit() .frame(width: 300, height: 200) .overlay( RoundedRectangle(cornerRadius: 0) .stroke(Color.white, lineWidth: 2)) } } .padding(.leading, 50) } } #Preview { BrandImage() }
Posted Last updated
.
Post not yet marked as solved
1 Replies
261 Views
Whenever we include the mergeable configuration on an xcframework which contains a SwiftUI preview, the preview can't compile. That's because it is trying to keep the dynamic configuration but on a binary type that is not a dynamic library. It fails with the error: Linking failed: linker command failed with exit code 1 (use -v to see invocation) 1d: -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) That's only happening when we add the preview.
Posted
by BertoGmFc.
Last updated
.
Post not yet marked as solved
4 Replies
528 Views
Hello, Very recently, the following code has automatically appeared at the bottom of three of my SwiftUI View files: @available(iOS 17.0, macOS 14.0, tvOS 17.0, visionOS 1.0, watchOS 10.0, *) struct $s10Accent_Ace33_0BADA584A03144EFDAB57154E6FD3FBALl7PreviewfMf_15PreviewRegistryfMu_: DeveloperToolsSupport.PreviewRegistry { static let fileID: String = "Accent_Ace/HistoryView.swift" static let line: Int = 47 static let column: Int = 1 static func makePreview() throws -> DeveloperToolsSupport.Preview { DeveloperToolsSupport.Preview { let randomWord1 = FetchWord.getRandomWord() let randomWord2 = FetchWord.getRandomWord() @State var randomWords = [Word(word: randomWord1.0, IPA: randomWord1.1, lineNumber: randomWord1.2), Word(word: randomWord2.0, IPA: randomWord2.1, lineNumber: randomWord2.2)] HistoryView(words: $randomWords) } } } This is from one of my files but it's very similar in the other two. It seems to have something to do with my previews. The problem is that this code generates an error: Ambiguous use of 'init(_:traits:body:)'. My previews worked just fine before the auto-generated code appeared, so I tried deleting it. However, it automatically comes back no matter how many times I get rid of it. It's preventing me from building my App Playground, so I can't run the app or even see the previews. Does anyone know how to get rid of it or fix the error? Thanks for the help!
Posted Last updated
.
Post not yet marked as solved
7 Replies
932 Views
It seem that Xcode preview compiler fail correctly parse generic and produce a "Failed to build" error: Proposed example: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ import CoreBluetooth import SwiftUI /// Working in preview /* struct InitialView&lt;S&gt;: View where S: StringProtocol { var body: some View { NestedView() } struct NestedView: View { var body: some View { Text("Hello") } } } struct WorkingView: View { var body: some View { InitialView&lt;String&gt;() } } */ /// Not working in preview struct NotWorking: View { var body: some View { InitialView&lt;String&gt;() } struct InitialView&lt;S&gt;: View where S: StringProtocol { var body: some View { NestedView() } struct NestedView: View { var body: some View { Text("Hello") } } } } struct ContentView_PreviewProviders: PreviewProvider { static var previews: some View { NotWorking() } } ^^^^^^^^^^^^^^^^^^^^^^^^^^^ investigating the SampleView.1.preview-thunk.swift from ~/Library/Developer/Xcode/DerivedData/.../ directory, I found that compiler translate the above code into pre-compiled stage using typealias without considering the Generic condition- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... extension NotWorking.InitialView.NestedView { typealias InitialView = NotWorking.InitialView typealias NestedView = NotWorking.InitialView.NestedView @_dynamicReplacement(for: body) private var __preview__body: some View { #sourceLocation(file: "/Users/giuseppe/Development/Private/Dev/MyPlayground/MyPlayground/SampleView.swift", line: 40) Text(__designTimeString("#32812.[2].[1].[1].[0].property.[0].[0].arg[0].value", fallback: "Hello")) #sourceLocation() } } extension NotWorking.InitialView { typealias InitialView = NotWorking.InitialView typealias NestedView = NotWorking.InitialView.NestedView @_dynamicReplacement(for: body) private var __preview__body: some View { #sourceLocation(file: "/Users/giuseppe/Development/Private/Dev/MyPlayground/MyPlayground/SampleView.swift", line: 35) NestedView() #sourceLocation() } } extension NotWorking { @_dynamicReplacement(for: body) private var __preview__body: some View { #sourceLocation(file: "/Users/giuseppe/Development/Private/Dev/MyPlayground/MyPlayground/SampleView.swift", line: 30) InitialView&lt;String&gt;() #sourceLocation() } } ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Should be considered a compiler bug or I missed something in my code?
Posted
by Giuma.
Last updated
.
Post marked as solved
17 Replies
4.2k Views
HI, I have an issue displaying SwiftUI previews with Xcode 14. My project has iOS and an watchOS Target. It also includes a lot of SPM, most of them only used by the PhoneApp. The project build successfully for both iOS and watchOS. I can see that when building the watch target, only SPM that are included in this target are build for for watchOS The issue is when I try to build a swiftUI preview of the watch target. In this case I can see on the build for Preview log that Xcode try to build ALL spm defined in the Xcode project, including the one that are not used by the watch Target, As a lot if spm are for iOS only, and doesn't build for watchOS, the build for preview fails, and I'm unable to preview my swiftUI views on the AppeWatch. Note that my project is working fine on Xcode 13. This issue is easy to reproduce in any Xcode projects containing a iOS and watchOS target by adding a SPM that is only for iOS. Any workaround to fix this issue ?
Posted Last updated
.
Post not yet marked as solved
8 Replies
1.7k Views
Hi, I am trying to use SwiftUI in my project where I was using UIKit only, until now. The problem is that Preview in Xcode is not working even for very simple View with Text("Hello World"). Code is correct and project is possible to build and run. Even when I try to select real device (real iPhone) I can see Preview in my device. But preview in simulator is not working. Can someone help me with this? I am attaching diagnostic from Xcode and file from ~/Library/Logs/DiagnosticReports/ Thanks for help xcode_preview.txt findmylocated-2023-11-08-133122.ips.txt
Posted
by Brut.
Last updated
.
Post not yet marked as solved
1 Replies
254 Views
Hello! I have been experiencing an issue where if I make a change to a file then preview breaks and I must rebuild the project to fix preview. I cant attach the diagnostic report unfortunately as its too big even after i compressed it. How should I proceed?
Posted Last updated
.
Post marked as solved
1 Replies
472 Views
I have a CoreData model with two entities, 'User' and 'Player', that both use 'Person' as their 'Parent Entity'. While the App appears to work correctly in the simulator, including with CloudKit via NSPersistentCloudKitContainer, I get a crash in Xcode Previews: libswiftCore.dylib [ AGScoringModel/Persistence.swift:183: Fatal error: #init(inMemory:): Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, reason=Cannot migrate store in-place: Cannot merge multiple root entity source tables into one destination entity root table, destinationURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, NSUnderlyingError=0x600000ce02a0 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={message=Cannot merge multiple root entity source tables into one destination entity root table, destinationRootEntity=Person, NSUnderlyingException=Cannot merge multiple root entity source tables into one destination entity root table, sourceRootEntities=( User, Player ), reason=Cannot merge multiple root entity source tables into one destination entity root table}}} ] Why is this? Something in my configuration for persistent container?
Posted
by GoZoner.
Last updated
.