Skip to content

Instantly share code, notes, and snippets.

@technocidal
Created February 7, 2024 12:07
Show Gist options
  • Save technocidal/28847f3da25fd4f6fbe3d70db560ca5d to your computer and use it in GitHub Desktop.
Save technocidal/28847f3da25fd4f6fbe3d70db560ca5d to your computer and use it in GitHub Desktop.
Optional selection
//: A UIKit based Playground for presenting user interface
import UIKit
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var selected: Int? = 1
var body: some View {
TabView(selection: $selected) {
Text("First View")
.tabItem {
Image(systemName: "1.circle")
Text("First")
}
.tag(Optional(0))
Text("Second View")
.tabItem {
Image(systemName: "2.circle")
Text("Second")
}
.tag(Optional(1))
Text("Third View")
.tabItem {
Image(systemName: "3.circle")
Text("Third")
}
.tag(Optional(2))
}
.tabViewStyle(.page)
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment