This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ExpandableButtonItem: Identifiable { | |
let id = UUID() | |
let label: String | |
private(set) var action: (() -> Void)? = nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ExpandableButtonPanel: View { | |
let primaryItem: ExpandableButtonItem | |
let secondaryItems: [ExpandableButtonItem] | |
private let noop: () -> Void = {} | |
private let size: CGFloat = 70 | |
private var cornerRadius: CGFloat { | |
get { size / 2 } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var showAlert: Bool = false | |
@State private var alertLabel: String = "" | |
var body: some View { | |
NavigationView { | |
ZStack { | |
// List | |
List(1...20, id: \.self) { i in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TodoItem: Identifiable { | |
let id = UUID() | |
let todo: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
struct TodoItem: Codable, Identifiable { | |
let id = UUID() | |
let todo: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var newTodo = "" | |
@State private var allTodos: [TodoItem] = [] | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var newTodo = "" | |
@State private var allTodos: [TodoItem] = [] | |
var body: some View { | |
NavigationView { | |
VStack { | |
HStack { | |
TextField("Add todo...", text: $newTodo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var newTodo = "" | |
@State private var allTodos: [TodoItem] = [] | |
var body: some View { | |
NavigationView { | |
VStack { | |
HStack { | |
TextField("Add todo...", text: $newTodo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
// ... | |
private func saveTodos() { | |
UserDefaults.standard.set(try? PropertyListEncoder().encode(self.allTodos), forKey: "todosKey") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
// ... | |
private func loadTodos() { | |
if let todosData = UserDefaults.standard.value(forKey: "todosKey") as? Data { | |
if let todosList = try? PropertyListDecoder().decode(Array<TodoItem>.self, from: todosData) { | |
self.allTodos = todosList | |
} | |
} |