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

163 Posts
Sort by:
Post not yet marked as solved
3 Replies
366 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
Post not yet marked as solved
2 Replies
482 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
by
Post marked as solved
1 Replies
336 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
Post not yet marked as solved
1 Replies
510 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
Post not yet marked as solved
3 Replies
428 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
Post not yet marked as solved
1 Replies
265 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
Post not yet marked as solved
4 Replies
533 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
by
Post not yet marked as solved
0 Replies
333 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
by
Post not yet marked as solved
1 Replies
255 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
by
Post marked as solved
1 Replies
473 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
Post not yet marked as solved
0 Replies
304 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
by
Post not yet marked as solved
0 Replies
340 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
by
Post not yet marked as solved
1 Replies
542 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
by
Post not yet marked as solved
2 Replies
443 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
by
Post not yet marked as solved
1 Replies
396 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
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
Post not yet marked as solved
2 Replies
487 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
by