SwiftUI changes in Xcode 11 Beta 3
Today release of Xcode 11 Beta 3 brings some change to SwiftUI components. I will highlight some obvious one, you can check the rest here.
NavigationButton -> NavigationLink
NavigationView {
List {
Text("Hello World")
NavigationLink(destination: Text("Detail")) {
Text("Detail")
}
}
.navigationBarTitle(Text("Navigation Title"))
}
PresentationButton -> PresentationLink
PresentationLink(destination: Text("Present"), label: { Text("Popup") })
.tabItemLabel -> .tabItem
We can finally use SF Symbol here and we can init .tabItem
with Image
and Text
directly without VStack
.
TabbedView {
Text("First")
.font(.title)
.tabItem { Text("First") }
.tag(0)
Text("Second")
.font(.title)
.tabItem {
Image(systemName: "circle")
Text("Second")
}
.tag(1)
}
New initializer for most views with label
Most SwiftUI views got a initializer accepting @ViewBuilder
as a label which quite verbose for most case where we just need simple Text
.
In this beta 3 those views get a new initializer which accept LocalizedStringKey
.
Instead of.
Button(action: {
print("Button tapped")
}) {
Text("Button")
}
We can shorten it with.
Button("Button") {
print("Button tapped")
}
You can checkout my compiled cheat sheet here.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
Become a patron Tweet ShareUISplitViewController in SwiftUI
WWDC session shows us a way to create UISplitViewController with NavigationView in SwiftUI. It finally works in Xcode 11 Beta 3.