Xcode Previews

RSS for tag

Create an app UI and configure almost everything your users see using Xcode Previews.

Posts under Xcode Previews tag

155 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Xcode 15 beta 1 failed to preview SwiftUI view in watchOS target
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.
8
6
3k
Oct ’23
Swift Package Manager "platforms" and Watch OS
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?
1
0
883
Jul ’23
macOS widget preview error
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
5
0
1.7k
Mar ’24
App crashes at runtime when attempting new way of declaring Previews in iOS 17
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!
3
1
1.4k
Jul ’23
Any better way to write multi-family Widget #Preview macro?
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() } ...
2
2
1.2k
May ’24
SampleData on Previews @MainActor issue
Hi all, I am trying to render my SwiftUI views that uses SwiftData classes using sample data using the approach shown in the example code of wwdc2023-10196: @MainActor #Preview { TripsWidgetEntryView() .modelContainer(PreviewSampleData.container) } Unfortunately this seems no longer valid. Indeed I get this error: I then tried to remove the @MainActor as suggested, but the error in then moved to another level: What do you suggest to be the best approach to have back my preview working? I am using Xcode Beta 4 - 15A5195m
4
0
780
Jul ’23
SwiftUI Previews error
Xcode: 14.3 Cocopods: 1.11.3 SwiftUI file Previews error for Xcode 14.3 , and my project is written in OC and Swift The following is the detailed error information, what may be the cause? Thanks a lot! = PREVIEW UPDATE ERROR: HumanReadableSwiftError ProviderError: ProviderError: noPreviewInfos(runDestination: Simulator - iOS 16.4 | iphonesimulator | arm64 | iPhone 14 Pro Max | no proxy, thunkConfiguration: <IDEBuildOperationConfiguration: 0x6000cc5510a0; buildParameters=<IDEBuildParameters:0x600070e4a580:action=build:command=<IDEConcretePrimitiveSchemeCommand:0x60000629abb0:Run>:config=Debug:dest=iPhone 14 Pro Max:arch=arm64:workspaceArena=<IDEWorkspaceArenaSnapshot: 0x60008415fe00>: overridingProperties=( { // Preview overrides (immutable) DSTROOT = 【𝗟𝗶𝘁𝗲𝗿𝗮𝗹𝗦𝘁𝗿𝗶𝗻𝗴:/Users/wj/Library/Developer/Xcode/DerivedData/MyApp-gljivierkfnnqydoswlgudwodyeg/Build/Intermediates.noindex/Previews/MyApp/ReleaseProducts】 ENABLE_PREVIEWS = 【YES】 OBJROOT = 【𝗟𝗶𝘁𝗲𝗿𝗮𝗹𝗦𝘁𝗿𝗶𝗻𝗴:/Users/wj/Library/Developer/Xcode/DerivedData/MyApp-gljivierkfnnqydoswlgudwodyeg/Build/Intermediates.noindex/Previews/MyApp/Intermediates.noindex】 SYMROOT = 【𝗟𝗶𝘁𝗲𝗿𝗮𝗹𝗦𝘁𝗿𝗶𝗻𝗴:/Users/wj/Library/Developer/Xcode/DerivedData/MyApp-gljivierkfnnqydoswlgudwodyeg/Build/Intermediates.noindex/Previews/MyApp/Products】 }, ): collectBuildTimeStatistics=NO collectTimelineMetrics=NO>:executionEnvironment=<IDEExecutionEnvironment: 0x2cf4c0550>:singleFileToBuild=(null):buildLog=(null):parallelizeBuildables=YES:dontActuallyRunCommands=NO:buildImplicitDependencies=YES:skipDependencies=NO:restorePersistedBuildResults=YES:enableIndexBuildArena=NO:buildables=( "<Xcode3TargetProduct:0x60010c4472a0:MyApp.app blueprint:<Xcode3Target:0x2ee0b7860:MyApp>>" ):subsetOfBuildables=(null):buildDescriptionID=(null):scheme=<IDEScheme:0x461aeff20:'MyApp'>:schemeTask=BuildAndCommand:clientInfo=(null)>, blueprintName: TaskActivity, sourceFilePath: /Users/wj/Desktop/international/MyApp/DependencesLib/MyAppLib/TaskActivity/TaskActivity/View/InviteFriend/InviteFriendView.swift, thunkVariantSuffix: __XCPREVIEW_THUNKSUFFIX__)
1
0
800
Aug ’23
Xcode15 beta 5 - I can't have multiple TextEditor in the same view (Preview only)
If I have the code below and do the following with preview on: Choose one of the TextEditors and start typing: works Go to another one. Start typing, the text shows only in the first one you chose. Try to delete the text while on the second (or third, or fourth) and you can't. Try to delete the text in the first one. It works. >.< If you check the preview console, you will see that the first variable is used forever. Is anyone having the same problem? So annoying having to run everything every single time. I'm running the Xcode on Sonoma 14.0. import SwiftUI struct TextStruct { var text1: String = "text1" var text2: String = "text2" } struct TextSummaryEditorView: View { @State private var textForSummary: String = "textForSummary" @State private var boomshakalaka: String = "boomshakalaka" @State private var textstruct: TextStruct = TextStruct(text1: "boo1", text2: "boo2") var body: some View { VStack { VStack { Text(textForSummary) TextEditor(text: $textForSummary) .textFieldStyle(PlainTextFieldStyle()) .font(.system(size: Config.defaultFontSize)) .padding() .background(Color("background").opacity(0.9)) .lineSpacing(10) .zIndex(1) .multilineTextAlignment(.leading) Text(boomshakalaka) TextEditor(text: $boomshakalaka) .textFieldStyle(PlainTextFieldStyle()) .font(.system(size: Config.defaultFontSize)) .padding() .background(Color("background").opacity(0.9)) .zIndex(0.9) Text(textstruct.text1) TextEditor(text: $textstruct.text1) .textFieldStyle(PlainTextFieldStyle()) .font(.system(size: Config.defaultFontSize)) .padding() .background(Color("background").opacity(0.9)) .lineSpacing(10) .zIndex(1) .multilineTextAlignment(.leading) Text(textstruct.text2) TextEditor(text: $textstruct.text2) .textFieldStyle(PlainTextFieldStyle()) .font(.system(size: Config.defaultFontSize)) .padding() .background(Color("background").opacity(0.9)) .zIndex(0.9) } .cornerRadius(Config.radioL) .onChange(of: boomshakalaka) { print(boomshakalaka) } Text("Button") } } } struct TextSummaryEditorView_Previews: PreviewProvider { static var previews: some View { VStack { TextSummaryEditorView() } .padding() .background(Color("background").opacity(0.4)) } }```
1
0
375
Aug ’23
Xcode 15: Disable the content margins for widget preview? (contentMarginsDisabled)
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?
2
0
2.3k
Mar ’24
Xcode Previews for UIKit not working
I am having an issue when previewing a UIKit ViewController. I am developing my app inside Pods framework which then I import and use in scene/app delegate. I tried to use UIKit to have SwiftUI previews. I conformed to UIViewRepresentable protocol and made a struct that conforms to PreviewProvider where I returned the current controller as some View. I have many external dependencies like Moya, Alamofire, SnapKit... I am building my components in Pods project. Which I import than into scene/app delegate to start the app. I am getting the error: "Cannot preview in this file; Unexpected error occurred". I went online and found some people saying that I need to disable Automatically Refresh Canvas setting. But it still doesn't work. I am then getting an error: "Cannot preview in this file; Update failed". I attached a file with a generated report from the error. I also cleaned the build folder and restarted my Mac. I am using Macbook Pro M2. If I run UIKit previews in a new project it works. But I need it to be able to run in my current project. https://www.notion.so/Xcode-Previews-UIKit-Error-Report-ba5ec69080f34cb09c6f93c6cd0131d7?pvs=4
2
0
1.6k
Oct ’23
SwiftUI Previews Not Working In Swift Packages (XCode 15 beta 6)
XCode Previews do not work when defined in a Swift Package in XCode 15 beta 6. The following error will be returned when trying to show a SwiftUI Preview: FailedToInstallAppError: Failed to install ”XCPreviewAgent.app” Could not install the preview host ”XCPreviewAgent.app” on iPhone 14 Pro ... HumanReadableNSError: Simulator device returned an error for the requested operation. Ensure your bundle contains a valid CFBundleShortVersionString. As far as I know, a Swift Package doesn't need a CFBundleShortVersionString declared? Am I missing something? Replicate Error To replicate the error, simply create a new SPM package from XCode, and create a Preview: struct Preview: PreviewProvider { static var previews: some View { Group { Text("Hello") } } } Does anyone know of any workaround this issue?
5
1
2.2k
Aug ’23
Provide a longer timeout for PreviewUpdateTimedOutError or a way to change it
A similar request was posted last year and the response was to request a generated report. This is unacceptable; we cannot preview our app reliably because we have to use a hybrid build because you insist on releasing framework updates piecemeal and NEVER back-porting them. So no, "generating a report" for you to fix whatever the delay is, will not work for us. PLEASE.. Give us a way to increase this timeout value in the project. You put us into this mess, give us a way to get out of it without having to wait on Apple engineers to "analyze" it.
0
0
273
Aug ’23
Xcode Canvas Simulator cause multiple diagnosticd processes to run and 100% CPU
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.
28
20
4.9k
Dec ’23
Xcode 15 beta 7 Previews building issue
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
35
10
22k
1w
Xcode Previews spawn multiple instances of my Mac app
I have a Mac app in Xcode using SwiftUI. Recently I noticed the Xcode's previews had become very sluggish, and after some sleuthing I discovered that was because when the previews were running, it would spawn a new instance of the app in the background for every keystroke, and never quits any of these instances. Here's a video where you can see the problem: https://static.squares.tv/Xcode%20Spawning%20720p.mov It's a document-based app where I'm doing a lot of Metal rendering, using different audio and video frameworks and extensions with custom networking so it's possible something is blocking the app's ability to quit easily. How do I troubleshoot this problem to figure out exactly what is preventing Xcode from operating cleanly here?
1
0
413
Aug ’23