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

160 Posts
Sort by:
Post not yet marked as solved
1 Replies
34 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
16 Replies
4.7k Views
Summary When trying to display SwiftUI previews, building the previews may fail with the following error: Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found ld: warning: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found Note that may app does not use CoreAudioTypes. Observation This issue seems to occur when two conditions are met: The SwiftUI view must be located in a Swift Package Somewhere in either the View or the #Preview a type from another package has to be used. Say I have to packages one named Model-package and one named UI-Package. The UI-Package depends on the Model-Package. If I have a SwiftUI view in the UI-Package that uses a type of the Model-Package either in the View itself or in the #Preview, then the described error occurs. If I have a View in the UI-package that does not use a type of the Model-Package anywhere in its View or #Preview then the SwiftUI Preview builds and renders successful. I created a bug report: FB13033812
Posted Last updated
.
Post not yet marked as solved
3 Replies
302 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
25 Replies
2.5k 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
134 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
1.8k 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
610 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
381 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
129 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
187 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
1.7k 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
143 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
.
Post not yet marked as solved
6 Replies
289 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 not yet marked as solved
0 Replies
133 Views
Hi, I am getting an error in the preview section for the watchOS application. But it works when I build it. I get the like following errors in Preview. How can I solve it? no such module 'QuartzCore' Compile RoundedCorners.swift (arm64): /Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/SourcePackages/checkouts/lottie-ios/Sources/Private/CoreAnimation/Animations/CAAnimation+TimingConfiguration.swift:4:8: error: no such module 'QuartzCore' import QuartzCore ^ Compile Shape.swift (arm64): /Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/SourcePackages/checkouts/lottie-ios/Sources/Private/CoreAnimation/Animations/CAAnimation+TimingConfiguration.swift:4:8: error: no such module 'QuartzCore' import QuartzCore ^ Compile LottieAnimationView.swift (arm64): /Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/SourcePackages/checkouts/lottie-ios/Sources/Private/CoreAnimation/Animations/CAAnimation+TimingConfiguration.swift:4:8: error: no such module 'QuartzCore' import QuartzCore ^ Copy FirebaseAnalyticsSwift.swiftmodule (arm64): error: /Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/Build/Intermediates.noindex/Previews/TestApp Mobil Watch App/Intermediates.noindex/Firebase.build/Debug-watchsimulator/FirebaseAnalyticsSwift.build/Objects-normal/arm64/FirebaseAnalyticsSwift.swiftmodule: No such file or directory (in target 'FirebaseAnalyticsSwift' from project 'Firebase')
Posted
by themsy.
Last updated
.