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

166 Posts
Sort by:
Post not yet marked as solved
1 Replies
280 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
568 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
974 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<S>: 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<String>() } } */ /// Not working in preview struct NotWorking: View { var body: some View { InitialView<String>() } struct InitialView<S>: 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<String>() #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.5k 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
265 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
492 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
.
Post not yet marked as solved
0 Replies
322 Views
Having MacBook Pro with macOS Monterey v 12.7.2 and Xcode 13.3 (13B113) I cannot find a Xcode simulator, which could provide iPhone 6.7" display for my first app's product page' Any advice? Thanks!
Posted Last updated
.
Post not yet marked as solved
0 Replies
360 Views
I am using the Observable macro and when I use @Environment property wrapper to instance my model the preview stop working. Sample code below my model Library import SwiftUI import Observation @Observable class Library { // ... } Now in my main app I created an instance of Library and add that instance to the environment @main struct BookReaderApp: App { @State private var library = Library() var body: some Scene { WindowGroup { LibraryView() .environment(library) } } } Now if I want to retrieve the Library instance from any view using the @Environment property wrapper the preview stop working completely struct LibraryView: View { @Environment(Library.self) private var library var body: some View { List(library.books) { book in BookView(book: book) } } } #Preview { LibraryView() } Check the 2 screenshots below Any idea why this is happening? Is there any workaround? I am working with Xcode Version 15.2. Thanks in advance for any kind of help!
Posted Last updated
.
Post not yet marked as solved
1 Replies
575 Views
Have a fairly large project in production and after updating Xcode from 14.x to 15.x the previews are no longer working. Devs in our team are using various Apple silicon machines. Error: == PREVIEW UPDATE ERROR: FailedToLaunchAppError: Failed to launch com.utr.utrplay ================================== | RemoteHumanReadableError: The operation couldn’t be completed. Transaction failed. Process failed to launch. (process launch failed) | | BSTransactionError (1): | ==error-description: Process failed to launch. | ==NSLocalizedFailureReason: Transaction failed. Process failed to launch. (process launch failed) | ==transaction: <FBApplicationProcessLaunchTransaction: 0x600003b240e0> | ==precipitating-error: Error Domain=FBProcessExit Code=64 "The process failed to launch." UserInfo={NSLocalizedFailureReason=The process failed to launch., BSErrorCodeDescription=launch-failed, NSUnderlyingError=0x600000c2fb40 {Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x600000c2ea90 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}}} | ==error-reason: process launch failed
Posted Last updated
.
Post not yet marked as solved
2 Replies
462 Views
https://developer.apple.com/forums/thread/731732 Possibly linked to the above issue The app compiles just fine, but SwiftUI Previews cannot build if there any any packages that lack support for visionOS I made sure that filters were enabled so that the package is only linked to iOS In a project that literally NEVER imports or uses an iOS only package, it fails completely == PREVIEW UPDATE ERROR: SchemeBuildError: Failed to build the scheme ”VisionHelloWorld” 'tracks(withMediaType:)' is unavailable in visionOS Compile LightCompressor.swift (arm64): /Users/bryananderson/Library/Developer/Xcode/DerivedData/VisionHelloWorld-dviwzruidaouzeeafminiifghzfe/SourcePackages/checkouts/LightCompressor_iOS/Sources/LightCompressor/LightCompressor.swift:123:47: error: 'tracks(withMediaType:)' is unavailable in visionOS guard let videoTrack = videoAsset.tracks(withMediaType: AVMediaType.video).first else { ^~~~~~ AVFoundation.AVAsset:17:15: note: 'tracks(withMediaType:)' has been explicitly marked unavailable here open func tracks(withMediaType mediaType: AVMediaType) -> [AVAssetTrack]
Posted Last updated
.
Post not yet marked as solved
1 Replies
409 Views
I've encountered while attempting to integrate SwiftUI into an existing UIKit project. Specifically, I have experienced recurring view crashes when creating new SwiftUI views within the project. My Feedback id is FB13509337 I would appreciate your assistance in resolving this matter promptly, as it is critical to the development of our application. Your prompt attention to this issue would be greatly appreciated
Posted
by Qazi09.
Last updated
.
Post not yet marked as solved
2 Replies
1k Views
I am having issues trying to use previews in the xcode 15.1. I am using MacOS Sonoma and iOS 17.2 and am struggling using previews. the preview never loads.it keeps on saying cannot preview in this file. previews_diagnostics_summary.txt
Posted
by sabby87.
Last updated
.
Post not yet marked as solved
2 Replies
509 Views
I have same code in Xcode and Playground. But Xcode is not previewing the View the right way. Here is a screenshot of Xcode: and here is the screen of Playground: when i run the code (command + R) it's working fine and i get the true preview in the app (just like what i get in Playground). Am I doing something wrong or is it a bug?
Posted Last updated
.
Post not yet marked as solved
0 Replies
387 Views
I'm using iXGuard for my Unity Project and need to build on XCode with iXGuard Toolchains (Xcode menu -> Toolchains -> select iXGuard Toolchains, and also need to add a new script for Post Action (Product -> Scheme -> Edit Scheme -> Archive -> Post-actions ) The question is how can I setup/add in Unity to configure for it instead of manual configure on Xcode?
Posted
by LeHuuChi.
Last updated
.
Post not yet marked as solved
1 Replies
341 Views
Hi, I just learn swiftUI and trying to preview it on my device (iPhone 15 Pro Max), however the app is failed to launch on my device. I haven't change anything on the code yet. Here's the error message from diagnostic == PREVIEW UPDATE ERROR: FailedToLaunchAppError: Failed to launch swplayground.MQ ================================== | MessageError: Connection interrupted | | ================================== | | | MessageSendFailure: Message send failure for &lt;ServiceMessage 28: relaunch&gt;
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.4k Views
I work on my project on two computers. One of them is older and stuck at Xcode 13. My project targets iOS 15+. Previously I was able to bounce back and forth between the two, checking code into source control in between. After doing a bunch of work on one of them over an extended period, I've returned to my older one and checked out the code... only to be unable to build because Xcode balks at every use of #Preview. I didn't change any project settings in the meantime, so I have no idea why this is suddenly a problem... Edit: It turns out that this is because previous versions of the SDK did not use this macro. Because I created a couple of new SwiftUI files on the newer OS and Xcode/SDK, it plopped #Preview into the new files instead of the previous implementation, PreviewProvider. I'll leave this post up for anyone who searches on this problem, since I found zero other references in a general Web search.
Posted Last updated
.