Questions tagged [swiftui-previews]

45 questions
12
votes
1 answer

SwiftUI Preview turns on microphone

Does anyone know how to stop swiftUI previews from turning the microphone on? I wear bluetooth headphones while I work and every time a preview boots up it enables the mic. This degrades my audio quality since the headphones then split their…
9
votes
1 answer

SwiftUI preview layout: size that fits does not work

I want my preview to only have the size of the view and not show the whole iPhone. I have already tried it with this code: struct TimerCardView: View { var body: some View { Text("Hello, World!") .padding() …
SwiftUI_Max
  • 201
  • 2
  • 6
8
votes
0 answers

Xcode can't generate previews with Swift Package

I'm getting this error because of a Swift package I have added to my project. HumanReadableSwiftError SettingsError: noExecutablePath() This is…
Berry Blue
  • 15,330
  • 18
  • 62
  • 113
7
votes
2 answers

Better Performance in SwiftUI: Creating a new view OR using a function with @ViewBuilder

When working with different view composition in SwiftUI, we can take two approaches: To use some @ViewBuilder function inside the view as a helper function: @ViewBuilder func makeButtonLabel() -> some View { if isPlaying { PauseIcon() …
Soheil Novinfard
  • 1,358
  • 1
  • 16
  • 43
6
votes
0 answers

Prevent main AppKit app window from opening when loading a SwiftUI preview

I have a Mac App that's mostly written in AppKit. Over time, I'm adding new views in SwiftUI, and all the while I've been using SwiftUI previews to preview both my new SwiftUI views, and my old AppKit views/view controllers (see Previews are not…
Alexander
  • 59,041
  • 12
  • 98
  • 151
6
votes
2 answers

SwiftUI Preview Sheet w/o Running Live Preview?

Update Xcode 13 The code sample below works as expected in Xcode 13. Update from Apple Frameworks Engineer October 2020: Unfortunately there is no current workarounds to let you preview this outside of the live preview. Is it possible to create a…
Clay Ellis
  • 4,960
  • 2
  • 37
  • 45
5
votes
1 answer

Swift UI previews in modular app with frameworks

Having an issue running the preview for SwiftUI views inside my framework. Here is a project structure. Preview for SwiftUI views that are in the main target ( ContentView, GradientView) work as expected. However, when I’m trying to preview the view…
Eugene P
  • 554
  • 4
  • 19
5
votes
0 answers

SwiftUI Preview not finding image of used framework

My project consists of a main iOS app project and three additional frameworks for Presentation, Domain and Data layers. My own frameworks are embedded in the main target. Third party frameworks are managed by CocoaPods and linked dynamically. Now if…
4
votes
0 answers

Preview locale does not work for Xcode 14.1

According to the documentation, we should be able to set the locale on previews and the following code should work: import SwiftUI struct TestView: View { var timeFormatter: DateFormatter { let formatter = DateFormatter() …
adauguet
  • 988
  • 8
  • 18
4
votes
0 answers

SwiftUI preview failure, Failed to launch swiftc: 'swiftc too many arguments' reason?

I have a large mixed language (obj-c, swift & c++) project, it builds and runs fine on all platforms "Build for previews" also seems to complete fine. Opening preview of a particular swift file fails, e.g.: Diagnostics gives: Failed to launch…
Nick Hingston
  • 8,724
  • 3
  • 50
  • 59
4
votes
1 answer

How can I preview a SwiftUI View shared between iOS and WatchOS?

I have a sample SwiftUI View I am using in a iOS with Apple Watch Extension and I am getting this error when I try to preview it in a WatchOS "Device": The run destination iPhone 12 mini is not valid for Running the scheme 'TestApp WatchKit App' I…
Gin Tonyx
  • 383
  • 1
  • 11
3
votes
0 answers

Previewing SwiftUI toolbars on macOS

Is there any way to preview the toolbar for a macOS SwiftUI app? I can't figure out how to structure my preview to get it to display the toolbar items in a view. It does the right thing when actually running, but not in preview. I’ve tried putting…
Rick
  • 3,298
  • 3
  • 29
  • 47
3
votes
0 answers

Is there a way to have SwiftUI Previews ignore specific files to prevent another build?

We have an MLPackage file in our SwiftUI project. Whenever we try to load Previews on a View file, Xcode gets stuck in an infinite loop of "Build for Previews". The builds succeed, but immediately start another build. So, there's no way to…
Nate Lowry
  • 391
  • 3
  • 9
3
votes
1 answer

Xcode - SwiftUI Preview Inside SPM Package Error "Could not find host for previews"

I am using a SPM package and added one simple DashboardView inside the package as below: import SwiftUI struct DashboardView: View { var body: some View { Text("Hello World") } } struct DashboardView_Previews: PreviewProvider { …
Enes F.
  • 406
  • 6
  • 17
3
votes
2 answers

Xcode 14 - Cannot preview in this file, Cannot connect to iPhone 14 | FailedToConnectToDTServiceHubError: Cannot connect to iPhone 14

while exploring the swiftUI and creating my first swiftUI app in Xcode, it is throwing an error for the preview saying - Cannot preview in this file, Cannot connect to [Device Name]. While it's working fine in simulator. In order to troubleshoot,…
Mohit G.
  • 1,157
  • 2
  • 12
  • 22
1
2 3