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 not yet marked as solved
2 Replies
1.3k Views
Hello, I'm new to Xcode and trying to understand the first programs. Unfortunately the buttons don't work in my preview and simulator. You can't trigger a click with the mouse. But as soon as you use your own iPhone instead of the simulator, the clicks or taps on the buttons work. With the Accessibility Inspector it is possible to control the buttons and trigger the click. Everything works fine on my MacBook Air, just not on my iMac. I haven't found anything similar on the forums either. I've already completely erased and reinstalled Xcode, swapped out the mouse and keyboard, tested various settings in Xcode and the simulator, and compared MacBook and iMac, all to no avail. The mouse does not trigger a click on the simulator. What do I have to set in the Xcode editor or in the simulator so that the buttons work in the preview and simulation mode? I'm really grateful for any help or advice. Xcode: Version 14.3.1 (14E300c) iOS16.4 iMac: 3.4GHz quad-core Intel Core i5 / 32GB 2400MHz DDR4 Simulator iPhone 14 / 13 Pro / SE (2.) / XS import SwiftUI struct ContentView: View { var body: some View { HStack { Button("Tap me") { print("tapped1") } Button("test") { print("tapped2") } } } } struct Previews_ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Posted
by
Post not yet marked as solved
1 Replies
1.5k Views
I am using a preview with my view that looks like this - #Preview { PaywallTwo(store: MyStore()) } In this scenario, MyStore is a MainActor, but has an initialiser doing some async work inside a Task from the initialiser. I am not sure if this is an implementation error, or perhaps something wrong with the new #Preview, as this was working fine with PreviewProvider I currently have complete strict concurrency, and the error I get is: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
Posted
by
Post not yet marked as solved
1 Replies
541 Views
I'm migrating my app from Obj-C to Swift. It uses Core Data, and most of the entities are implemented in Obj-C. I just took a stab at converting one of my views to SwiftUI, and it runs correctly, but Preview crashes with executeFetchRequest:error: A fetch request must have an entity.. I've tried declaring the fetch request both with and without the entity: argument: @FetchRequest(entity: NewsItem.entity(), sortDescriptors: []) var newsItems : FetchedResults<NewsItem>
Posted
by
Post not yet marked as solved
1 Replies
376 Views
Xcode can not show a preview of my ContentView.swift file and every time it crashes. I have attached the log file: Log
Posted
by
Post not yet marked as solved
1 Replies
591 Views
Failed to launch app"..." in reasonable time. Creating a new SwiftUI app, trying to show the preview for ContentView.swift before selected another file in the project before selecting ContentView.swift Finally , trying to show the view preview creates a 'Failed to launch app "..." in reasonable time' along with the attached error diagnostic. Also, MobileCal and PowerShell can, after a few minutes, quit unexpectedly. Their diagnostics are also attached. Can't upload files a the moment
Posted
by
Post not yet marked as solved
1 Replies
468 Views
Hi, I am trying to develop a simple app that records punches on a heavy bag through my Apple Watch. When I successfully build and try to use it on my watch, it does not load and I get the message on Xcode **Cannot preview this file.** Cannot connect to *** apple watch I am trying to attach the "previews diagnostics" file generated from the Diagnostics icon but I continuously get an error message, so I will screenshot the initial window simctl_diagnose_log.txt SerializationErrors.txt Thank you for your support, Nikos
Posted
by
Post not yet marked as solved
4 Replies
764 Views
I am trying to create a new project using XCode 15 beta 2 for VisionOS and I am not able to see the preview window. I tried with 3 projects and all of them have the same result: You can see that the Preview is stuck with a loading icon and the status bar shows the message: Building <project_name> for Previews | RealityKitContent_RealityKitContent 11/64. Any ideas?
Posted
by
Post marked as solved
1 Replies
689 Views
For my app I use a struct for my CoreData persistence controller like so: struct PersistenceController { static var shared = PersistenceController() // more code omitted for brevity } As a development asset I made an extension to the PersistenceController to provide a special instance for previews with some sample data. extension PersistenceController { static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) // create some sample data return result }() } Now I want to use the special preview instance with the new #Preview macro in Xcode beta 2. The deployment target for the app is set to iOS 17. #Preview { var context = PersistenceController.preview.container.viewContext return SpanList() .preferredColorScheme(.light) .environment(\.managedObjectContext, context) } But the preview fails to build due to the following error: Type 'PersistenceController' has no member 'preview'. My experiments show that everything I add to the PersistenceController via an extension is not available in the preview macro. This is no matter where I place the extension. Even when it’s placed in the same file as the PersistenceController itself. Am I missing something or is this intended behaviour?
Posted
by
Post not yet marked as solved
0 Replies
307 Views
Hi, I'm learning to program with Swift using the tutorials on the Apple Developer site. I use the latest version of Xcode (14.3.1) and continuing in the "SwiftUI Tutorial" where I have to build an app called Landmarks, I get an error and it doesn't let me see the preview. It says there is an error in the "ModelData.swiftui" file but I can't figure it out, as I followed all the steps in the tutorial. If anyone had the same problem and can help me, I'd be very happy. Thanks in advance
Posted
by
Post not yet marked as solved
1 Replies
800 Views
I'm working on an app and want to include a Watch target. My app uses Swift Package Manager and 1 package (that I created) for doing repetitive utilities such as showing a "Loading..." view (in iOS only) The Swift Package Package has supported platforms set to: platforms: [ .iOS(.v14) ] However, when I try to start editing my Watch OS SwiftUI ContentView, the preview errors out stating: iOS storyboards do not support target device type "watch". (This is from the Swift Package's Loading.storyboard.) The Swift Package is UIKit only - no Swift UI. The "Loading..." view I am using for iOS is a View Controller - obviously not meant for Watch OS. I cannot run the target to the Watch app - it shows a lot of UIKit errors from the Swift Package, like Cannot find type 'UIView' in scope and on and on. The Watch app does not need this package at all. I thought that if the platforms does not specify .watchOS* then it wouldn't try to apply it to my Watch target. How do I tell this target not to link/load this package?
Posted
by
Post not yet marked as solved
1 Replies
526 Views
It is my first time using it, in the middle of a course. I am using macOS 10.15.7, as I understand 12.4 of Xcode is the latest I can use. I have tried restarting and going through other questions in the forum and couldn't find anything to help me. Here is a link to a screen shot: https://ibb.co/9twdcv1
Posted
by
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
Post not yet marked as solved
0 Replies
660 Views
Is there a way to get previews to load products from the configuration file? I tested in both our own app and in the SKDemo app, appears that the StoreView is empty and not products are loaded in previews. The products loads fine form the config file when running the demo app in the simulator.
Posted
by
Post not yet marked as solved
1 Replies
1.3k Views
Hello everyone. I'm pretty new to developing for iOS, I just started a couple of weeks ago, so apologies if I don't use the correct terminology on certain occasions. I also did attempt to search both these forums, as well as the change log for iOS 17 Developer Beta 3 to see if this was a known issue, and I didn't see anything reporting it, so again, apologies if this is known. I was just posting this because, being new, I didn't want to jump to the conclusion that It was an issue with the compiler. I actually already jumped the gun once and submitted a Feedback ticket where an Image was rendering just fine in the Preview of Xcode, but not on device, and was told that it was my code 🤦, so I'd rather not have a repeat 😅. As I'm sure most of you have seen, iOS 17 allows a much shorter way to declare previews: #Preview { ContentView() } Compared to the previous way in iOS 16 and before: struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } However, when I attempt to run my code, if any of my Views are using the new method of declaring Previews, the app will crash immediately at runtime with the following error: dyld[583]: Symbol not found: _$s21DeveloperToolsSupport17UVPreviewRegistryCMn Expected in: /System/Library/Frameworks/DeveloperToolsSupport.framework/DeveloperToolsSupport I have tested this with a brand new project on both an iPhone XR and an iPhone 14 Pro. It actually worked on iOS 17 Beta 1, but ceased working on Beta 2, and still does not function on Beta 3. The only constant is the device that I physically do the developing, my MacBook, as I remember seeing a message about it copying over symbols to each device before it would let me remotely deploy or preview my code to either of my phones, so if this isn't an issue with the betas, I wonder if it could be related perhaps to that. Let me know if you have experienced anything similar! Again, super sorry if this has been reported on already. If you just want to point me in the right direction, then I'll do the reading! Thanks!
Posted
by
Post not yet marked as solved
2 Replies
815 Views
Hello together, I'm currently learning CoreData, but my preview in Xcode crashes always when I try to add something new to the view. Does someone have an idea what I need to pass to the preview that it works? My code
Posted
by
Post marked as solved
1 Replies
1.1k Views
Hello, In WidgetKit, I have to write multiple #Preview macros for each family the widget supports. So is there any better way to write the #Preview? (Although I can use the legacy PreviewProvider but it does not support timeline to test transition animation.) #import WidgetKit #import SwiftUI struct DailyCaffeineWidget: Widget { ... } @available(iOS 17.0, *) #Preview("Inline", as: .accessoryInline) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Circular", as: .accessoryCircular) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Rectangular", as: .accessoryRectangular) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Small", as: .systemSmall) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } @available(iOS 17.0, *) #Preview("Medium", as: .systemMedium) { DailyCaffeineWidget() } timelineProvider: { previewTimelineProvider() } ...
Posted
by
Post not yet marked as solved
1 Replies
378 Views
In Xcode 12 through 15, every time I open a file with a PreviewProvider in it, Xcode opens the preview automatically. 99% of the time, I just want to look at some code, so I immediately have to close the preview. Can we at least have an option to disable this? Feedback: FB7871978
Posted
by