Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active July 18, 2020 21:19
Show Gist options
  • Save sturdysturge/1a3ec6ddf1a3d2f12f12479ce33de1bc to your computer and use it in GitHub Desktop.
Save sturdysturge/1a3ec6ddf1a3d2f12f12479ce33de1bc to your computer and use it in GitHub Desktop.
RevDoc Toolbar
import SwiftUI
public struct ToolbarView: View {
@State var data: [String]
init() {
var data = [String]()
for _ in 1...5 {
data.append(UUID().uuidString)
}
self._data = State<[String]>(initialValue: data)
}
public var body: some View {
NavigationView {
List(data, id: \.self) { uuid in
Text(uuid)
.lineLimit(1)
}
.navigationTitle("UUID Generator")
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button("Add") {
data.append(UUID().uuidString)
}
.padding(5)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(5)
}
ToolbarItem(placement: .navigationBarLeading) {
Button("Delete All") { data.removeAll() }
}
ToolbarItem(placement: .bottomBar) {
Button("Sort A > Z") { data.sort() }
}
ToolbarItem(placement: .bottomBar) {
Button("Sort A > Z") { data.sort(by: >) }
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment