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

SwiftUI Preview not rendering
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
8
0
2.3k
Jan ’24
SwiftUI preview : PropertyListError: Property list missing value for required key "binaryType"
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
1
0
654
Nov ’23
Xcode Preview keeps crashing
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
2
0
508
Nov ’23
Failed to build the scheme no such module in Preview WatchOS
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')
0
1
520
Oct ’23
Is there any way to speed up SwiftUI Previews?
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?
1
0
1.5k
Oct ’23
Xcode 15 - Preview Crashes with error log but works when parent view is Pinned
Hello I am in need of help to try and understand what is going on with XCode and Previews when using Swift Data. I have the following path: View 1 (Calandar Screen) -> Passes Model -> View 2 (Details Screen) I have a situation where when working on View 2 it will not run in Preview mode when the Pin is not selected. However if I pin View 1 and then go to work on View 2 preview works fine. Now I am guessing that this might have something to do with Swift Data and by having View 1 open it generates the Model to be passed but I might be wrong? I am also struggling to understand and read the error log that excode generates. I have Preview setup in View 2 as follows #Preview { DiaryReadView(diaryModel: DiaryModel()) .environmentObject(NavigationStateManager()) .modelContainer(for: [DiaryModel.self], inMemory: true) } Error Log ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Incident Identifier: 5C8FAD15-959E-4E0A-AFF4-55A739D54110 CrashReporter Key: CC891733-97EE-34E0-EDB7-394B181A2623 Hardware Model: iMac20,1 Process: Diary [36381] Path: /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/78258A6C-0145-4E82-ACCD-1F0539F2148A/data/Containers/Bundle/Application/970BD3F5-925F-47BD-A214-7F7B0226A04F/Diary.app/Diary Identifier: OR-1 Version: 1.0 (1) Code Type: X86-64 (Native) Role: Foreground Parent Process: launchd_sim [29471] Coalition: com.apple.CoreSimulator.SimDevice.78258A6C-0145-4E82-ACCD-1F0539F2148A [78195] Responsible Process: SimulatorTrampoline [48509] Date/Time: 2023-10-24 10:55:15.3444 +0100 Launch Time: 2023-10-24 10:55:14.7909 +0100 OS Version: macOS 14.0 (23A344) Release Type: User Report Version: 104 Exception Type: EXC_BAD_INSTRUCTION (SIGILL) Exception Codes: 0x0000000000000001, 0x0000000000000000 Termination Reason: SIGNAL 4 Illegal instruction: 4 Terminating Process: exc handler [36381] Triggered by Thread: 0 Thread 0 Crashed: 0 libswiftCore.dylib 0x7ff814aa36f2 0x7ff814a76000 + 186098 1 SwiftData 0x7ff84952f7dd 0x7ff849514000 + 112605 2 SwiftData 0x7ff8495b1746 0x7ff849514000 + 644934 3 SwiftData 0x7ff8495b64c9 0x7ff849514000 + 664777 4 SwiftData 0x7ff84956f726 0x7ff849514000 + 374566 5 Diary 0x10a4e9635 DiaryModel.init() + 357 (@__swiftmacro_5Diary0A5Model0B0fMm_.swift:2) 6 Diary 0x10a4e94c2 DiaryModel.__allocating_init() + 34 7 DiaryReadView.1.preview-thunk.dylib 0x10bf15533 closure #1 in static $s025Diary_PreviewReplacement_A10ReadView_133_E76E9AE78936AC4C16C3EA33E995B161Ll0B0fMf_15PreviewRegistryfMu_.makePreview() + 51 (@__swiftmacro_025Diary_PreviewReplacement_A10ReadView_133_E76E9AE78936AC4C16C3EA33E995B161Ll0B0fMf_.swift:9) 8 PreviewsInjection 0x10ac7f386 0x10ac41000 + 254854 9 PreviewsInjection 0x10ac8025d 0x10ac41000 + 258653 10 libswift_Concurrency.dylib 0x7ff85b04c76c 0x7ff85b03b000 + 71532 11 PreviewsInjection 0x10ac7f0e5 0x10ac41000 + 254181 12 PreviewsInjection 0x10ac83108 0x10ac41000 + 270600 13 PreviewsInjection 0x10ac83c1c 0x10ac41000 + 273436 14 PreviewsInjection 0x10ac70a0d 0x10ac41000 + 195085 15 PreviewsInjection 0x10ac7387a 0x10ac41000 + 206970 16 PreviewsInjection 0x10ac5a630 0x10ac41000 + 103984 17 PreviewsInjection 0x10ac5aaf4 0x10ac41000 + 105204 18 PreviewsInjection 0x10ac753f0 0x10ac41000 + 214000 19 PreviewsInjection 0x10ac493f3 0x10ac41000 + 33779 20 PreviewsInjection 0x10ac48a85 0x10ac41000 + 31365 21 PreviewsFoundation 0x10b741df9 0x10b6a1000 + 658937 22 libdispatch.dylib 0x7ff800156a90 0x7ff800155000 + 6800 23 libdispatch.dylib 0x7ff800157d3a 0x7ff800155000 + 11578 24 libdispatch.dylib 0x7ff800166ac0 0x7ff800155000 + 72384 25 libdispatch.dylib 0x7ff800166526 0x7ff800155000 + 70950 26 CoreFoundation 0x7ff8003f5850 0x7ff800368000 + 579664 27 CoreFoundation 0x7ff8003f018b 0x7ff800368000 + 557451 28 CoreFoundation 0x7ff8003ef409 0x7ff800368000 + 553993 29 GraphicsServices 0x7ff80fcdd187 0x7ff80fcda000 + 12679 30 UIKitCore 0x7ff805b703a2 0x7ff804b95000 + 16626594 31 UIKitCore 0x7ff805b74e10 0x7ff804b95000 + 16645648 32 SwiftUI 0x7ff84a61077e 0x7ff8495ce000 + 17049470 33 SwiftUI 0x7ff84a610637 0x7ff8495ce000 + 17049143 34 SwiftUI 0x7ff84a2bcaa5 0x7ff8495ce000 + 13560485 35 Diary 0x10a4ffade static DiaryApp.$main() + 30 36 Diary 0x10a500099 main + 9 (DiaryApp.swift:12) 37 dyld_sim 0x10ab023ee start_sim + 10 38 dyld 0x10cd9c3a6 0x10cd96000 + 25510
1
0
737
Oct ’23
Is it possible to create relationships between objects in previews?
Is it possible to create one-to-many relationships between optional objects in SwiftData Xcode Previews? The below code I call from #Preview crashes the canvas on the post.authors?.append(tempAuthors.randomElement()!) when I try to append an array to an optional array. I can append the previewAuthors array to the authors array in the simulator or on device, but it crashes in Preview. My running theory is it has something to do with being in memory since this works on device, but I'm not sure that I missed something super obvious. static func previews(_ count: Int) -> [Post] { let previewAuthors = [Author(name: "..."), Author(name: "...")] var posts: [Post] = [] for i in 0..<count { let post = Post(title: "Title \(i)") post.authors?.append(previewAuthors.randomElement()!) posts.append(post) } return posts }
2
0
634
Oct ’23
Xcode 15.01 Preview "Failed to launch app *** in reasonable time"
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
3
0
1.2k
Dec ’23
Xcode 15 Preview not working with generic nested view
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?
7
0
1.2k
Jan ’24
Xcode 15 preview crashes Xcode
Hi, Having various problems with Xcode. Finally got it to load the runtimes and now when I try to preview, either with the old method or #Preview, the preview panel icon spins and the folder view refreshes several times until Xcode finally crashes with a SIGABRT. I've sent feedback, but not sure if I will hear back. I've tried with public 15.0, 15.0.1 RC and 15.1 Beta. All the same. The status bar at the top changes between 'Packages | Fetching' and 'Indexing | Processing Files', while the Folder list on the left keeps refreshing. About 10 refreshes later and Xcode crashes. Running directly in the simulator works, although it does take a long time to start after the app has loaded. This is with iOS 17.0 as the target or with 16.0. I cleared out all the previews with: xcrun simctl --set previews delete all Which saved some space but didn't help. Thanks, Darren
4
1
1k
Oct ’23
Xcode 15 Previews not working for watchOS apps
I'm using Xcode 15 15A240d Similarly to https://developer.apple.com/forums/thread/731732 when I try to run the Xcode previews for watchOS views in a watchOS target I get compilation errors from UIKit code. This is only valid for Xcode Previews. Building the code normally / Run it on simulator or device works. I don't understand why Xcode attempts to build iOS code. my scheme does include the host app for the watch I made a duplicate of that scheme by unchecking the host app and that makes previews work again. I'm not sure this is the intended behavior. I double checked and this was not the case with Xcode 14.3.1 I could run the initial target without issues on Xcode previews. Do you experience the same issue? is this a problem with my scheme settings or an Xcode bug?
0
0
518
Oct ’23
Please Help!Xcode15 Archive has error:Command PhaseScriptExecution failed with a nonzero exit code
Hello, everything worked fine when I packaged my APP with the old version of Xcode, but I started reporting this error when I archived the package with Xcode15. I hope to get your help, thank you. error: Build target App of project App with configuration Release PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users/wang/Library/Developer/Xcode/DerivedData/App-dcarpmhimruyzxfuqacwgyqbpwsy/Build/Intermediates.noindex/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/Script-9592DBEFFC6D2A0C8D5DEB22.sh (in target 'App' from project 'App') cd /Users/wang/Documents/new-bn-app/bn-app/ios/App /bin/sh -c /Users/wang/Library/Developer/Xcode/DerivedData/App-dcarpmhimruyzxfuqacwgyqbpwsy/Build/Intermediates.noindex/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/Script-9592DBEFFC6D2A0C8D5DEB22.sh mkdir -p /Users/wang/Library/Developer/Xcode/DerivedData/App-dcarpmhimruyzxfuqacwgyqbpwsy/Build/Intermediates.noindex/ArchiveIntermediates/App/BuildProductsPath/Release-iphoneos/App.app/Frameworks Symlinked... rsync --delete -av --filter P .*.?????? --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Capacitor.framework" "/Users/wang/Library/Developer/Xcode/DerivedData/App-dcarpmhimruyzxfuqacwgyqbpwsy/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app/Frameworks" building file list ... rsync: link_stat "/Users/wang/Documents/new-bn-app/bn-app/ios/App/../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Capacitor.framework" failed: No such file or directory (2) done sent 29 bytes received 20 bytes 98.00 bytes/sec total size is 0 speedup is 0.00 rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/d9889869-120b-11ee-b796-7a03568b17ac/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9] Command PhaseScriptExecution failed with a nonzero exit code
3
0
1.3k
Oct ’23