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 marked as solved
2 Replies
369 Views
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..<6) {index in Image(systemName: "star.fill") .font(.largeTitle) .foregroundColor(.gray) .onTapGesture { rating = index } } } } } #Preview { MaskBootCamp() }
Posted
by bxw0405.
Last updated
.
Post not yet marked as solved
26 Replies
4.4k Views
The Xcode Canvas Simulator (for Xcode 14 and even 15 ..beta 6) cause multiple springboard and diagnosticd processes to run at nearly 100% CPU , cause the MacBook M1 to heat. This happens every time. This is usually triggered after the Canvas show an error which live previewing the code as I edit it. I have tried clearing the derived data but it doesn't seem to help. This happens with all projects. I am unable to use live previews because of this issue. The are often other processes with the string Poster in them. Like PhotosPosterProvider , CollectionsPoster , ExtragalacticPoster running high on usage at the same time.
Posted
by diiiv9.
Last updated
.
Post not yet marked as solved
1 Replies
962 Views
Hi all, when I am trying to build a preview I am always getting the error "Failed to launch app in reasonable time". When clicking on Diagnostics I get the following report information: AppLaunchTimeoutError: Failed to launch app ”SwiftUI-Weather.app” in reasonable time The app ”SwiftUI-Weather.app” did not launch on ”iPhone 15 Pro” in 15 seconds. bundle identifier: tregnet.SwiftUI-Weather device name: iPhone 15 Pro path: /Users/MyUser/Library/Developer/Xcode/DerivedData/SwiftUI-Weather-fvxpuqojpxxuqtbuzmjvlatlmuqy/Build/Intermediates.noindex/Previews/SwiftUI-Weather/Products/Debug-iphonesimulator/SwiftUI-Weather.app Also clicking on "Generate Report" in the Diagnostics menu is not doing anything for me, even after waiting for a few minutes. Any help would be appreciated. Greetings
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.2k Views
Hey guys, anybody knows how to fix issues with the keyboard on Xcode in preview mode? it used to work well for me but has now stopped working, see details. Problem statement: Cannot use the keyboard in previews. For example, typing in a textfield does nothing. Everything works well in simulator. Environment: macOS Monterey 12.6 Xcode 14.1 Thanks in advance for your input.
Posted Last updated
.
Post not yet marked as solved
2 Replies
511 Views
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
Posted
by TSHKS.
Last updated
.
Post not yet marked as solved
1 Replies
314 Views
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.
Posted Last updated
.
Post not yet marked as solved
1 Replies
543 Views
Hello, SwiftUI previews are not working in my project : when I try to display the preview in Xcode, I got this error : And if I click on the help icon, here is the complete error message : RemoteHumanReadableError: Invalid preview service message on ServiceHub channel ================================== | RemoteHumanReadableError | | PropertyListError: Property list missing value for required key ”binaryType” | Property list: ["agentRole": previews, "environment": { | "DYLD_FRAMEWORK_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator"; | "DYLD_LIBRARY_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator"; | "OS_ACTIVITY_DT_MODE" = YES; | "PACKAGE_RESOURCE_BUNDLE_URL" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphoneos"; | "SQLITE_ENABLE_THREAD_ASSERTIONS" = 1; | "XCODE_RUNNING_FOR_PREVIEWS" = 1; | "__XCODE_BUILT_PRODUCTS_DIR_PATHS" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator"; | "__XPC_DYLD_FRAMEWORK_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator"; | "__XPC_DYLD_LIBRARY_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator"; | }, "__unique_service_message_identifier": 4, "deviceEnvironment": { | "SIMULATOR_CAPABILITIES" = "/Applications/Xcode 14.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone 14 Pro Max.simdevicetype/Contents/Resources/capabilities.plist"; | "SIMULATOR_DEVICE_NAME" = iPhone4Simulator; | "SIMULATOR_LEGACY_ASSET_SUFFIX" = iphone; | "SIMULATOR_MAINSCREEN_HEIGHT" = 2796; | "SIMULATOR_MAINSCREEN_PITCH" = "460.000000"; | "SIMULATOR_MAINSCREEN_SCALE" = "3.000000"; | "SIMULATOR_MAINSCREEN_WIDTH" = 1290; | "SIMULATOR_MODEL_IDENTIFIER" = "iPhone15,3"; | "SIMULATOR_PRODUCT_CLASS" = D74; | }, "agentIdentifier": { | bundleID = "com.apple.dt.XCPreviewAgent"; | discriminant = bundleID; | }, "displaySize": { | height = 932; | width = 430; | }, "deviceIdentifier": com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro-Max, "processType": application, "arguments": <__NSArray0 0x1b9e04f48>( | | ) | , "workspaceID": E4CEE565-58C6-4EB5-94F1-7A9F48791515, "deviceType": simulated, "payloadUsedAgentIdentifier": 1, "frameBufferMaskPath": /Applications/Xcode 14.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone 14 Pro Max.simdevicetype/Contents/Resources/framebuffer.pdf, "displayScale": 3, "bundleID": com.apple.dt.XCPreviewAgent] ================================== | MessageSendFailure: Message send failure for <ServiceMessage 4: relaunch> Is there anyone who already encountered this error message? Or maybe anyone who have any idea how to solve it? Thanks, Alexandre
Posted Last updated
.
Post not yet marked as solved
5 Replies
2.7k Views
Hi, we recently starting moving toSwiftUI and unable to preview. we are getting a below crash. App is running using Rosetta on M1 Mac Xcode 14 iOS 16 All we did is to enable swift previews in build settings. Crash report for SwiftUI preview: PotentialCrashError: Update failed XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application. ================================== |  RemoteHumanReadableError |   |  LoadingError: failed to load library at path "/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin": Optional(dlopen(/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin, 0x0000): tried: '/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin' (errno=2), '/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/BiometricLogin.framework/BiometricLogin' (errno=2)) |   |  ================================== |   |  |  MessageSendFailure: Message send failure for &lt;ServiceMessage 17: update&gt;
Posted
by vamsi.ac.
Last updated
.
Post marked as solved
1 Replies
911 Views
Hello, I've created multiple Entity in CoreData, that has a relationship to one another. However, I'm unable to create @discardableResult to use in SwiftUI preview. /// Entity data for use with canvas previews. static var preview: Entity1 {         let entities1 = Entity1.makePreviews(count: 1)         return entities1[0] } @discardableResult static func makePreviews(count: Int) -&gt; [Entity1] {         var contents = [Entity1]()         let viewContext = PersistenceController.preview.container.viewContext         let persistenceController = PersistenceController.shared         for index in 0..&lt;count {             let entities1 = Entity1(context: viewContext)             entities1.id = UUID()             entities1.title = "Amazing day!"             let photo = Photo(context: viewContext)             let imageData = UIImage(named: "Golden Temple")?.jpegData(compressionQuality: 1) ?? Data()             photo.linkedToJournal = journal             let thumbnail = Thumbnail(context: viewContext)             let thumbnailData = persistenceController.thumbnail(with: imageData)?.jpegData(compressionQuality: 1)             thumbnail.data = thumbnailData             thumbnail.photo = photo             let photoDataObject = PhotoData(context: viewContext)             photoDataObject.data = imageData             photoDataObject.photo = photo             contents.append(entities1)         }         return contents } You may also try to use the sample code from https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users to build a SwiftUI Preview. Appreciate if you could suggest how to build a SwiftUI preview as it saves a lot of development effort and time. Thank you very much!
Posted
by kaviraja.
Last updated
.
Post not yet marked as solved
3 Replies
767 Views
MacBook Air m2 with Sonoma 14 and Xcode 15. When running simulator or preview of IOS app, the laptop rapidly heats to an alarming degree. According to activity monitor there is not excessive CPU. This is the IOS 17 version. I saw a suggestion to try 16.4. But in Xcode 15 I cannot see the pathway to change the IOS version. You can create a simulator for it, but Xcode still only sees IOS 17.
Posted
by miray.
Last updated
.
Post not yet marked as solved
2 Replies
394 Views
Ich bin neu bei Xcode und habe einen Fehler gemacht, bei dem ich nicht weiß, wie ich ihn beheben soll. Das war mein Code zuerst: #Preview { AddLektionView().modelContainer(for: Lektion.self) } und dann habe ich bemerkt, dass er so aussehen sollte: #Preview { AddLektionView().modelContainer(for: Lektion.self, inMemory: true) } Nun stehe ich vor dem Problem, dass die Preview die Daten auf Dauer gespeichert hat und ich beim ändern vom Aufbau der Daten, die gespeichert werden sollen, einen Fehler erhalte, da die neue App eine veraltete Datenstruktur von SwiftData lädt, was der App nicht passt. Daraufhin erhalte ich dann einen Fehler, dass die Daten wegen der unbekannten neuen Variable nicht geladen werden können. Wie kann ich die, von SwiftData geladenen Daten entfernen, sodass die Preview (Canvas) wieder funktioniert? (Eine Neuinstallation von Xcode habe ich schon probiert) Ich danke für jede Hilfe! Mit freundlichen Grüßen Tobias
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
We have a fairly large app with dozens of dependencies. SwiftUI Previews take ages to build, even though they are only using a fraction of our code. I managed to speed them up a bit by disabling most of my custom build phases. But they are still super slow due to how long it takes to build things like Firebase. Anyone have any ideas here? Is there a way to ensure that previews are only compiling the files that they need to work?
Posted
by Xaxxus.
Last updated
.
Post marked as solved
8 Replies
2.8k Views
Hello! I can't preview the SwiftUI views of watchOS target in Xcode 15 beta 1, when the containing iOS app has a SPM dependency. Reproducing steps: Create a new watchOS app project (with a companion iOS app) in Xcode 15. Both iOS and watchOS ContentView can be previewed at this step. Add a Swift package to the iOS target (the package should be an iOS-specific package, not a watchOS one, for example, https://github.com/siteline/SwiftUI-Introspect) After you add the static library to iOS target, the watchOS preview no longer work anymore. If you check the error message, you can find the Xcode preview attempt to build the iOS package against watchOS SDK.
Posted
by Gong.
Last updated
.
Post not yet marked as solved
1 Replies
406 Views
== DATE: Thursday, October 26, 2023 at 13:06:58 China Standard Time 2023-10-26T05:06:58Z == PREVIEW UPDATE ERROR: FailedToLaunchAppError: Failed to launch com.*** ================================== | MessageError: Unexpected message object | | Unexpected message object: expected ProcessID, got Optional(6872)
Posted
by popipo.
Last updated
.