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 deleteTodo(at offsets: IndexSet) { | |
self.allTodos.remove(atOffsets: offsets) | |
saveTodos() | |
} | |
} |
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
private let emojiList: [EmojiItem] = [ | |
EmojiItem( | |
emoji: "👾", | |
name: "Alien Monster", | |
description: "A friendly-looking, tentacled space creature with two eyes."), | |
EmojiItem( | |
emoji: "🥑", | |
name: "Avocado", | |
description: "A pear-shaped avocado, sliced in half to show its yellow-green flesh and " | |
+ "large brown pit."), |
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 DetailsView: View { | |
let emojiItem: EmojiItem | |
var body: some View { | |
VStack(alignment: .leading) { | |
HStack { | |
EmojiCircleView(emojiItem: emojiItem) |
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 EmojiItem: Identifiable { | |
let id = UUID() | |
let emoji: String | |
let name: String | |
let description: 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 { | |
private let emojiList: [EmojiItem] = [ | |
EmojiItem( | |
emoji: "👾", | |
name: "Alien Monster", | |
description: "A friendly-looking, tentacled space creature with two eyes."), | |
EmojiItem( | |
emoji: "🥑", | |
name: "Avocado", | |
description: "A pear-shaped avocado, sliced in half to show its yellow-green flesh and " |
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 EmojiCircleView: View { | |
let emojiItem: EmojiItem | |
var body: some View { | |
ZStack { | |
Text(emojiItem.emoji) | |
.shadow(radius: 3) | |
.font(.largeTitle) |
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 { | |
// ... | |
var body: some View { | |
NavigationView { | |
List(emojiList) { emojiItem in | |
HStack { | |
EmojiCircleView(emojiItem: emojiItem) | |
Text(emojiItem.name) | |
.font(.headline) | |
}.padding(7) |
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 { | |
// ... | |
var body: some View { | |
NavigationView { | |
List(emojiList) { emojiItem in | |
NavigationLink(destination: EmptyView()) { | |
HStack { | |
EmojiCircleView(emojiItem: emojiItem) |
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 { | |
// ... | |
var body: some View { | |
NavigationView { | |
List(emojiList) { emojiItem in | |
NavigationLink(destination: DetailsView(emojiItem: emojiItem)) { | |
HStack { | |
EmojiCircleView(emojiItem: emojiItem) | |
Text(emojiItem.name) |