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
4 answers

SwiftUI NavigationView extra space at bottom of screen

I am new to Swift and I'm trying to create a simple screen with the NavigationView in SwiftUI. For some reason it is adding extra space at the bottom when I wrap anything inside of the NavigationView. I wanted to see if anyone else is running into…
JakeRuth
  • 191
  • 1
  • 6
10
votes
2 answers

@State vs @ObservableObject - which and when?

I'm currently getting familiar with SwiftUI and Combine frameworks. And I'm not really getting the difference between these two approaches. When we have to keep track of some data (say, a list of tasks), we can declare a @State variable, and it's…
Alex.K
  • 234
  • 4
  • 12
10
votes
2 answers

How to fix gray bar under List in NavigationView in TabView?

So I am having a problem where just below my list I am having a gray bar that appears and when I click on a cell to go to the other view there is an even bigger gray bar. Here is the code for the List View: VStack{ NavigationView{ …
Ben O
  • 228
  • 1
  • 15
10
votes
1 answer

I want to tap a push notification to open a specific screen in SwiftUI

I am using SwiftUI. I want to open a specific screen other than Root View by clicking the push notification. There are several ways to open it using StoryBoard, but not without StoryBoard. How can I achieve it without using StoryBoard? I tried this,…
Ika
  • 1,271
  • 1
  • 12
  • 20
10
votes
2 answers

How to apply a context menu to buttons in a SwiftUI list row?

When I'm long-pressing on a button in list row, all of context menus for all buttons are shown. It looks like the whole list row is selected. How can I make it so that the context menu is shown only for the pressed button? I've seen this question…
Benjamin Angeria
  • 335
  • 4
  • 14
10
votes
1 answer

SwiftUI MVVM Coordinator/Router/NavigationLink

I am having problems to translate UIKit architecture patterns to SwiftUI. My current pattern is mostly MVVM with Coordinators/Routers. The MVVM part seems quite easy and natural with the addition of @ObservableObject/@Published. But the…
Darko
  • 9,655
  • 9
  • 36
  • 48
10
votes
0 answers

SwiftUI ScrollView and alignment

Okay, I know SwiftUI is a shift in thinking, especially coming from a world of HTML and css. But I've spent like 4 days trying to get something to work that I feel should be pretty easy and just can't so please help! I have an app where one screen…
Lamprizzle
  • 115
  • 2
  • 5
10
votes
2 answers

How to use ForEach on a NSSet generated by CoreData in SwiftUI

I generated a CoreData model with some 1-to-many relationships. Now I want to use a ForEach on this relationship which is a NSSet, then I'm getting the following error: Generic struct 'ForEach' requires that 'NSSet' conform to…
gurehbgui
  • 14,236
  • 32
  • 106
  • 178
10
votes
2 answers

SwiftUI navigation bar title and items does not disappear when swiping back fails

The problem is that the title and the item of the navigation bar does not disappear which is an unexpected behaviour. struct DestinationView: View { @State private var showingActionSheet = false var body: some View { Text("DestinationView") …
Viktor Maric
  • 443
  • 1
  • 4
  • 10
10
votes
7 answers

How to change DatePicker's texts color in SwiftUI?

I saw this question but it doesn't work in SwiftUI. Changing text color of datepicker I tried .forgroundColor and .accentColor but they don't change the texts' color.
BabakHSL
  • 622
  • 1
  • 8
  • 18
10
votes
2 answers

Interaction of DragGesture and ScrollView in SwiftUI

In an app I'm working on, there is a part that has, mostly, a "forward" navigation – tapping on buttons would display the next slide. However, a secondary "backward" navigation is also necessary. Here's the approach I've used: import SwiftUI struct…
Baglan
  • 1,057
  • 10
  • 23
10
votes
2 answers

Way to get selected tab index from TabView in SwiftUI

I've just added TabView, which is working fine, but I unable to fetch the selected tab index out if it. I think I've kept my code perfectly fine, not sure what's wrong. struct DefaultTabbar: View { @State private var selectedItem = 1 …
Kiran Jasvanee
  • 6,362
  • 1
  • 36
  • 52
10
votes
3 answers

How to iterate/foreach array in SwiftUI

I have this array of dictionaries. let deckColors = [ ["name": "blue", "desc": "desc1"], ["name": "yellow", "desc": "desc2"], ] And my view: struct ContentView: View { var body: some View { ForEach(0 ..< deckColors.count) {value…
user2641891
  • 143
  • 1
  • 1
  • 7
10
votes
5 answers

Programmatically detect Tab Bar or TabView height in SwiftUI

I have a SwiftUI app that will have a floating podcast player, similar to the Apple Music player that sits just above the Tab Bar and persists across all tabs and views while the player is running. I have not figured out a good way to position the…
eResourcesInc
  • 948
  • 1
  • 9
  • 17
10
votes
2 answers

SwiftUI: Cancel TapGesture on parent view

I have view hierarchy in SwiftUI like ParentView { //other views ChildView().highPriorityGesture(TapGesture().onEnded { print("Tap!") }) // other views }self.gesture(tap) And I want to have parent…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
1 2 3
99
100