Questions tagged [swiftui]

SwiftUI is a way to build user interfaces across all Apple platforms. Build user interfaces for any Apple device using one set of tools and APIs. With a declarative Swift syntax that’s easy to read and natural to write, SwiftUI works seamlessly with Xcode design tools to keep your code and design perfectly in sync. Automatic support for Dynamic Type, Dark Mode, localization, and accessibility. Use this tag for questions about SwiftUI on any platform.

SwiftUI is a closed-source Apple framework providing a declarative Swift-only API for defining the appearance and behavior of graphical user interfaces. Apple's reference documentation describes SwiftUI as follows:

SwiftUI provides views, controls, and layout structures for declaring your app's user interface. The framework provides event handlers for delivering taps, gestures, and other types of input to your app, and tools to manage the flow of data from your app's models down to the views and controls that users will see and interact with.

Though apps can now be built fully with SwiftUI, using the SwiftUI lifecycle, one can also embed the top-level SwiftUI View in an appropriate hosting adapter for the platform (NSHostView, NSHostingController, UIHostingController, or WKHostingController) for apps with non-SwiftUI lifecycles.

SwiftUI integrates with Apple's older imperative AppKit, UIKit, and WatchKit frameworks. An NSView or UIView can embed a SwiftUI View and vice versa.

SwiftUI supports live previews and dynamic replacement (hot swapping) in Xcode 11 on macOS 10.15 (Catalina) and later, and on devices running an operating system that supports SwiftUI (see the list below).

Apple first revealed SwiftUI at WWDC on June 3, 2019 and made it available in the first beta release of Xcode 11.

SwiftUI is part of the following SDKs:

  • macOS 10.15 (Catalina) and later,
  • iOS 13 and later,
  • tvOS 13 and later,
  • watchOS 6 and later.

SwiftUI apps cannot be deployed to older platforms.

In addition to the official documentation, Apple offers two tutorials (Introducing SwiftUI and the first part of Develop Apps for iOS) entirely devoted to SwiftUI, as well as sample code (Fruta: Building a Feature-Rich App with SwiftUI).

35593 questions
10
votes
1 answer

viewWillAppear() or other equivalent in SwiftUI

I'm looking for an event in the life-cycle of a view in SwiftUI, that is equivalent to viewWillAppear(). Yes, I know there is an ".OnAppear" in SwiftUI, but that is like viewDidAppear. Is there a workaround to do get that specific execution time…
Ethan Halprin
  • 470
  • 3
  • 11
10
votes
3 answers

SwiftUI - How to access UIHostingController from SwiftUI

I have SwiftUI page, it's being navigated from UIKit view. I want to set a title to this page, what I'm doing is // code of UIKit view let controller = UIHostingController(rootView: SwiftUIView()) controller.title =…
Leo Yang
  • 113
  • 1
  • 5
10
votes
2 answers

How can I remove maximize, minimize and close button in macOS in SwiftUI-life cycle?

I am working on a project for removing maximize, minimize and close buttons which we can see in every window in every App/projects build with Xcode for macOS in SwiftUI-life cycle. How could I do this? PS: Please consider I am coding on…
ios coder
  • 1
  • 4
  • 31
  • 91
10
votes
1 answer

Change SwiftUI ProgressView Color - macOS not iOS

I am attempting to create a white ProgressView spinner on macOS using SwiftUI / Swift 5.2 using: ProgressView() .progressViewStyle(CircularProgressViewStyle(tint: Color.white)) .accentColor(Color.white) However this does not seem to change…
Edward S.
  • 331
  • 2
  • 15
10
votes
0 answers

How to use TabView or ScrollView for carousel?

I'm trying to create a carousel like some of Apple's apps. The TabView has the paged style but it doesn't "peek" at the previous and next elements. The ScrollView(.horizontal) doesn't snap. I'm hoping for a mixture of the two behaviours without…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
10
votes
4 answers

How to create the equivalent of a SwiftUI stack view spacer programmatically

I'm working on trying to recreate the first SwiftUI Tutorial in code without using SwiftUI. In the example, it mentions using a Spacer "to direct the layout to use the full width of the device": VStack { Text("Turtle Rock") HStack { …
Andrew
  • 227,796
  • 193
  • 515
  • 708
10
votes
4 answers

Hide chevron/arrow on NavigationLink when displaying a view, SwiftUI

I am trying to remove the chevron that appears on the right of the screen with a navigationLink that contains a view. This is my code below: NavigationView { List { NavigationLink(destination: DynamicList()) { …
HarryW
  • 155
  • 2
  • 7
10
votes
3 answers

Hide SwiftUI DisclosureGroup Arrow and Remove Default Padding

I'm trying to make a fully custom list of expandable sections that have projects inside them in SwiftUI. This is how I want it to look in the end: I think I have the SwiftUI code set up right, but I'm having trouble finding view modifiers to…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
10
votes
2 answers

Fix hundreds of lines of warnings re layout constraints from DatePicker

Using the new (iOS 14) DatePicker in SwiftUI, it works as expected and looks fine in the simulator & on the device, BUT as soon as the calendar pops up, I get a few HUNDRED lines of warning in the output window. Which is a little annoying! While…
ConfusionTowers
  • 911
  • 11
  • 34
10
votes
3 answers

SwiftUI onHover doesn't register mouse leaving the element if mouse moves too fast

I've made some custom slider views in SwiftUI that change appearance based on hover state, but if the mouse moves out too fast (which is actually a very reasonable speed of moving a cursor), it stays in the hover state until you re-hover and…
max
  • 366
  • 3
  • 9
10
votes
1 answer

SwiftUI 2 pop to root view with no Scene delegate

I would like to refresh root view when user logs out but I can’t find how to do it under the new Scene-less SwiftUi 2. Next is @Swissmark posted solution I'm trying to implement in SwiftUI 2: let contentView = AppRootView(showingView:…
Matias Masso
  • 1,670
  • 3
  • 18
  • 28
10
votes
4 answers

How do I create a slider in SwiftUI for an Int-type property?

I have a view with with an Int property named "score" that I want to adjust with a slider. struct IntSlider: View { @State var score:Int = 0 var body: some View { VStack{ Text(score.description) Slider(value:…
Melodius
  • 2,505
  • 3
  • 22
  • 37
10
votes
3 answers

Why am I getting "Instance method 'background(_:alignment:)' requires that 'UIColor' conform to 'View'"?

I would like to understand why am I having issue with the background()? Instance method 'background(_:alignment:)' requires that 'UIColor' conform to 'View' var body: some View { Button("MY BUTTON") { print("the action") } …
David
  • 1,241
  • 20
  • 36
10
votes
1 answer

How to disable the device rotation animation in SwiftUI?

For UIKit to disable the device rotation animation you could override the viewWillTransitionToSize method. Disable orientation change rotation animation But what would be the best way to achieve this in SwiftUI?
adelmachris
  • 332
  • 2
  • 13
10
votes
1 answer

SwiftUI swizzling disabled by default, phone auth not working

I am building a screen with phone number login. I checked over and over again and the project is newly created, however, I am getting this log: 7.2.0 - [Firebase/Auth][I-AUT000015] The UIApplicationDelegate must handle remote notification for phone…
Marian Pavel
  • 2,726
  • 8
  • 29
  • 65