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

164 Posts
Sort by:
Post not yet marked as solved
0 Replies
33 Views
I'm seeing some weird behavior with conditional compilation when I use a build configuration other than "Debug" or "Release", and I'm wondering if I'm doing something wrong or if this is an Xcode bug. The setup Xcode version: 15.3 I have a simple SwiftUI view that takes in a model and displays an attribute of the model. struct ContentView: View { let model: Model var body: some View { VStack { Text("Name: \(model.name)") } .padding() } } In the model file, I have the struct definition, but also an extension that defines some sample data for use in SwiftUI previews: struct Model { let id: String let name: String } #if DEBUG extension Model { static let example = Model( id: "50fef362-f53d-4ded-9168-b887ff62e59d", name: "John Doe" ) } #endif And finally, I have a preview provider that uses this sample data: #Preview { ContentView(model: Model.example) } Normal behavior With the default "Debug" build configuration, this works just fine. There are no compilation errors, and the preview renders as expected. The issue Start off by changing the name of the build configuration to, e.g. "DebugDev" Now I start seeing seeing a mis-match between what happens and what Xcode tells me is happening. The code still compiles and runs, and the SwiftUI preview still works, but Xcode is displaying things as if it doesn't compile. Xcode formats the conditionally compiled code with a lower opacity color as if DEBUG isn't defined: In the view file, I now see a compilation error when referencing the conditionally-compiled code: Autocomplete doesn't work when trying to reference the conditionally compiled code Additional details/observations I have confirmed that the DEBUG active compilation condition is still defined in the build settings. All I've done is change the name of the build config I was initially thinking this might have something to do with the fact that this appears in a preview provider, since those are treated a bit differently, but the same thing happens if I reference the conditionally compiled code directly in the view class Another theory: since I was referencing conditionally compiled code from code that wasn't conditionally compiled, maybe Xcode was trying to tell me that wasn't valid. So, I tried placing the code that calls the conditionally compiled code (in this case, the view class) inside an #if DEBUG. This does get rid of the displayed compilation error, but auto-complete still doesn't work, and the whole class is displayed with the lower-opacity font. Help? I feel like I must be missing something. The only alternative I can think of is that Xcode has some logic hard-coded with the default "Debug" build config, and that would be...just silly.
Posted
by nivektric.
Last updated
.
Post not yet marked as solved
2 Replies
216 Views
With the newest version of Xcode (15.3) I cannot get Preview to load and am getting the following error: HumanReadableSwiftError CancellationError: CancellationError() I'd had this same issue a few months ago and opening up an older project's previews and then opening the project I was working on would allow Preview to show. The last few weeks I've not been getting this error and after 3 or 4 days not being in Xcode I'm getting this same error again. I'm relatively new to Xcode and Swift so not being able to load the darn preview and work through tutorials after seemingly doing the exact same thing I've been doing for months is quite ridiculous and frustrating. Any ideas on how to resolve this issue would be greatly appreciated.
Posted Last updated
.
Post not yet marked as solved
1 Replies
94 Views
On May 1 I started to see this image instead of watch UI preview. It worked well before. I didn't update Xcode, neither I deleted or installed any new simulator OS. It was harmful to my work, since simulator download is 4GB and I need to wait when it downloads, instead of reviewing PRs and closing tasks. Did anyone had the same issue? Do you know how to prevent it?
Posted
by kelin.
Last updated
.
Post not yet marked as solved
2 Replies
106 Views
So like the title says, when I start up Xcode the preview won;t work till I run a debug session using the simulator. Sometimes the debug session is unable to start the simulator, which I can start manually then run a debug session. Once all the above is done, preview works. Any idea what is causing this behavior?
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
7 Replies
3.1k Views
The Build for Previews builds all my targets including the test targets. Is there a way to configure the relevant targets? I do not see an option in the schema editor, and disabling Find Implicit Dependencies has no effect either.
Posted
by chkpnt.
Last updated
.
Post not yet marked as solved
1 Replies
129 Views
Hi All, I have been using Xcode for less than 5 months. Recently I get a problem that my previews does not load, even when I created a new project on a local disk. The Project builds, but the preview does not. The error I saw from the Diagnostics window is as below == PREVIEW UPDATE ERROR: HumanReadableSwiftError CancellationError: CancellationError()
Posted
by alex_fh.
Last updated
.
Post not yet marked as solved
1 Replies
122 Views
I referred to the code provided in the article Adding and Editing Persistent Data in Your App in the SwiftData documentation and tested the "/PreviewHelper" approach. I found that if a model class contains a property of a struct, and that struct includes a Set property or an Array property, the Preview would throw an error. Here is an example of the model: @Model class Book { // ... var someStruct: SomeStruct // ... } struct SomeStruct: Codable { // ... var someCollection: Set<Int> // ... } In actuality, this model can run and store data without any issues, but it fails to run in the Preview. Is there a problem with the implementation of this Preview or is there any other reason? Are there better ways to perform Preview in SwiftData?
Posted
by LandFish.
Last updated
.
Post not yet marked as solved
1 Replies
140 Views
Hi, I have had this issue since I started working again in iOS this year with Xcode 15. What happened to the SwiftUI Previews? My problem is that they are stuck forever in the Loading screen "Preparing iPhone Simulator for Previews". I now test the code on the actual Simulator and waiting for Xcode 16 to fix this. The characteristics of my project are: Using Swift Package Manager (10+ dependencies) Using Unit Tests and Test Plans. Using macOS Ventura (reverted from Sonoma because it's even worse) Macbook Air M1 - 16GB of RAM. I have tried everything including: Erasing derived data. Restarting. Reinstalling the whole computer. Reverting Sonoma to Ventura. Reverting Xcode 15.2 to 15.1 and 15.0.1. Using Previews_Provider and #Previews {} Using completely empty projects to test previews. Please help. Thanks
Posted Last updated
.
Post marked as solved
7 Replies
2k Views
I have an iOS app by using a swift package to hold most of the logic. However, the previews of SwiftUI views often fail with following error: HumanReadableSwiftError BuildError: failedToGenerateThunkInfo(Error Domain=com.apple.xcbuild Code=19 "could not generate preview info: noTargetBuildGraph" UserInfo={NSLocalizedDescription=could not generate preview info: noTargetBuildGraph}) To reproduce this, please clone https://github.com/pointfreeco/isowords and check for preview of ChangelogView.
Posted
by surajb.
Last updated
.
Post not yet marked as solved
2 Replies
200 Views
Sorry about my English, I'm using a translator. I'm taking a programming course with Swift in Xcode and one of the steps is to drag a control from the library into the view to place it below another control (both are "text"). In the preview, there is a text in the center of the mobile screen. In the video, open the library window with Shift + Command + L; then drag a "text" control to the preview that simulates a mobile phone and a stripe appears below the text control that I mentioned before, which means that that text will be placed below it. If you put it on top, then the line appears on top and the same if you put it on the sides. I have the option that appears below the phone, the one that says "Selectable", activated, so that I can select what I want in that phone simulation. The fact is that when I drag the text control from the library and try to put it below or in another position with respect to the text that already exists, it does nothing. The stripes do not appear, nor do you set the control. What could it be due to? I am using Xcode 15.3 Thank you.
Posted
by Vrebe.
Last updated
.
Post marked as Apple Recommended
1.9k Views
Hi guys, I am migrating my widgets to iOS 17 and because I already manage my layout margins, I just want to disable to new built-in widget content margins. I did it by using ".contentMarginsDisabled()" on the WidgetConfiguration and it works fine at run time. WIDGET CODE struct MyWidget: Widget { let kind: String = "MyWidget" var body: some WidgetConfiguration { return IntentConfiguration(kind: kind, intent: MyWidgetIntent.self, provider: WidgetProvider<MyWidgetIntent>()) { entry in WidgetView<MyWidgetIntent>(entry: entry) } .configurationDisplayName("My Widget") .supportedFamilies([WidgetFamily.systemMedium]) .contentMarginsDisabled() // <-- HERE } } RESULT Nevertheless, when previewing the WidgetView in a WidgetPreviewContext I didn't find anyway to disable the content margins (because manipulating directly the view and not a WidgetConfiguration). PREVIEW CODE struct MyWidget_Previews: PreviewProvider { static var previews: some View { WidgetView<MyWidgetIntent>(entry: WidgetEntry<MyWidgetIntent>()) // .padding(-16) Need to add this negative padding to disable margin .previewContext( WidgetPreviewContext(family: .systemMedium)) } } Do you know how to disable the content margins for widget preview?
Posted
by Clem23.
Last updated
.
Post not yet marked as solved
3 Replies
371 Views
Hi all, I am trying to create a widget for my app but I cannot use the Preview feature of Xcode. Xcode enters a build loop and builds the project over and over. There is no error or message. There is only a loading spinner and lots of build. It doesn't matter how much time I wait, it never finishes. I tried to clean the build folder, delete all preview simulators, quit, and reopen the XCode but nothing helped.
Posted Last updated
.
Post not yet marked as solved
5 Replies
1.5k Views
Following article Creating a widget extension on developer.apple.com (https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension) I encountered a problem with XCode preview: it shows an error with message | RemoteHumanReadableError: Failed to launch agent | No plugin is registered to launch the process type widgetExtension. Can someone help me? macOS 13.4 XCode 14.3.1
Posted
by Ratka6.
Last updated
.
Post not yet marked as solved
30 Replies
18k 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
2 Replies
366 Views
Hello! I'm studying swift in college now, and have encountered a problem previewing my code using canvas. Here's part of the code: struct ContentView: View { ......(omitted) var body: some View{ ScrollView{ cards Spacer() cardsAdjuster } } The canvas panel looks all right with the line "ScrollView", as the image shows, with the only problem that "cardsAdjuster" moves with the cards. But if I remove the line "ScrollView", the panel went wrong: As the image displays, all parts of body are displayed separately, and I can't find any setting options to merge them. (Take a look at the top of the screenshot) The problem is also found on my classmate's Xcode 12 running on macOS Monterey. Looking forward to your reply and thoughts. Thank you all!!
Posted
by RoddySu.
Last updated
.
Post not yet marked as solved
1 Replies
224 Views
I am new to Xcode and trying to learn and having issues with errors it seems. I believe the problem is specifically with my code not being able to be displayed on the example iPhone on the right hand side of the screen. Here are the 2 errors I receive below. The codes at the very bottom are red on my screen so I am guessing those are what is most important out of all of this. Thanks and please let me know if I can answer any additional questions regarding this. Ld /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Products/Debug-iphonesimulator/Playground.app/Playground normal (in target 'Playground' from project 'Playground') cd /Users/tward/Desktop/Playground.swiftpm /Users/tward/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target x86_64-apple-ios15.2-simulator -isysroot /Users/tward/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk -L/Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -L/Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Products/Debug-iphonesimulator -L/Users/tward/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib -F/Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -F/Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Products/Debug-iphonesimulator -F/Users/tward/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -iframework /Users/tward/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -iframework /Users/tward/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk/Developer/Library/Frameworks -filelist /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/Playground.build/Debug-iphonesimulator/Playground.build/Objects-normal/x86_64/Playground.LinkFileList -Xlinker -rpath -Xlinker @executable_path/../lib -dead_strip -Xlinker -object_path_lto -Xlinker /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/Playground.build/Debug-iphonesimulator/Playground.build/Objects-normal/x86_64/Playground_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Users/tward/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/Playground.build/Debug-iphonesimulator/Playground.build/Objects-normal/x86_64/Playground.swiftmodule -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/Playground.build/Debug-iphonesimulator/Playground.build/Playground.app-Simulated.xcent -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __ents_der -Xlinker /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/Playground.build/Debug-iphonesimulator/Playground.build/Playground.app-Simulated.xcent.der -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Intermediates.noindex/Playground.build/Debug-iphonesimulator/Playground.build/Objects-normal/x86_64/Playground_dependency_info.dat -o /Users/tward/Library/Developer/Xcode/DerivedData/Playground-aoepzfpfzcxxqggglpllgxkoywsr/Build/Intermediates.noindex/Previews/Playground/Products/Debug-iphonesimulator/Playground.app/Playground ld: entry point (_main) undefined. for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Posted
by Tybward.
Last updated
.