Xcode Previews

RSS for tag

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

Posts under Xcode Previews tag

153 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Swift UI NavigationLink Oval Button Needs to Disappear
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() }
0
0
448
Feb ’24
Previews Crash on CoreData model using 'Parent Entity'
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?
2
0
622
Jan ’24
Previews crashing when using @Environment property wrapper
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!
1
0
509
Jan ’24
Xcode 15.x previews not working
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
1
0
752
Jan ’24
Cannot preview visionOS apps because of Packages that do not support visionOS
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]
2
0
595
Jan ’24
Xcode Preview is not working
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
1
0
477
Jan ’24
Not able to preview on iPhone device
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;
1
0
393
Dec ’23
All of a sudden Xcode says "Use of unknown directive #Preview" in SwiftUI
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.
1
2
1.8k
Dec ’23
Getting Preview Crashed with the Red X
I am getting Preview Crash. If I remove line 30 below. then the Preview Crash does not occur. I have Restarted XCode, I have done a Project Clean, Then did a project rebuild. I have also Created a new Project from scratch Named the project Debug, Add one new View File named MaskBootCamp once I select MaskBootCamp The Preview willl Crash with an Circle with a Red X in the center With Preview Crashed. If I remove line 22 all is resolved and no exception occurs Is this a Swift Bug or some error in the coding? Excepition Report listed below the code. report Below: ** MaskBootCamp .swift ** import SwiftUI struct MaskBootCamp: View { @State var rating: Int = 0 var body: some View { ZStack{ starsView .overlay(overlayView.mask(starsView)) } } private var overlayView: some View { GeometryReader { geometry in ZStack(alignment: .leading) { Rectangle() .foregroundColor(.yellow) .frame(width: CGFloat(rating) / 5 * geometry.size.width) } //allowsHitTesting(false) } } private var starsView: some View { HStack{ ForEach(1..&lt;6) {index in Image(systemName: "star.fill") .font(.largeTitle) .foregroundColor(.gray) .onTapGesture { rating = index } } } } } #Preview { MaskBootCamp() }
3
0
474
Dec ’23
swiftUI code preview fatally crashing.
Hello! Being a beginner in creating and editing views using swiftUI, I am unsure of the current situation that I am presently in, and would be grateful for any advice or suggestions for the below problem. For some context, I have recently begun exploring the "Capturing depth using the LiDAR camera" Documentation using AVFoundation and intend to change its ContentView file which is currently written in swiftUI. The problem: I am unable to preview the SwiftUI code. When I try to resume the Preview Pane on the right
3
1
600
Dec ’23
Xcode Previews break when using ScrollViewProxy + Preferences
I'm working on a horizontally scrollable header view. I'd like to implement the following behavior: when users tap on the left/rightmost header items, the header would scroll so they become fully visible. I am using a custom PreferenceKey to report the selected index: struct SelectedTabPreference: PreferenceKey { static var defaultValue: Int = 0 static func reduce(value: inout Int, nextValue: () -> Int) {} } Then in my view, I wrap my content inside a ScrollViewReader to scroll to the selected header: struct ContentView: View { let tabs: [DrawerTab] @State private var selectedIndex: Int = 0 var body: some View { ScrollViewReader { scrollProxy in ScrollView(.horizontal, showsIndicators: false) { TopTabView(options: tabs, selectedIndex: $selectedIndex) .padding(32) .background(Color.clear.preference(key: SelectedTabPreference.self, value: selectedIndex)) } .onPreferenceChange(SelectedTabPreference.self) { value in let firstTabSelected = value == 0 let lastTabSelected = value == tabs.count - 1 guard firstTabSelected || lastTabSelected else { return } withAnimation { let anchor: UnitPoint = firstTabSelected ? UnitPoint(x: 0.1, y: 0) : UnitPoint(x: 0.9, y: 0) scrollProxy.scrollTo(tabs[value], anchor: anchor) } } } } } This works well when I run the app, but the Xcode Preview only shows a white screen. In fact, if I include this view as a subview in other views, their previews also break. The Preview only returns to life if I remove the programmatic scrolling: scrollProxy.scrollTo(tabs[value], anchor: anchor) I'm pretty sure this has to do with the ScrollViewProxy as my other Preference-based layouts work with Previews, but I don't know how to resolve the issue. Xcode Previews are an integral part of my workflow, and I'd like to avoid losing them if there's a chance.
1
0
375
Nov ’23