Created
October 21, 2019 20:27
-
-
Save renanzinho/4bc35bcf166201a2c7c4aeb2c13d0157 to your computer and use it in GitHub Desktop.
This file contains 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
import SwiftUI | |
import Combine | |
class Item: ObservableObject, Identifiable { | |
var title: String | |
var id: UUID = UUID() | |
@Published var done: Bool = false | |
init(title: String) { | |
self.title = title | |
} | |
} | |
class Items: ObservableObject { | |
@Published var items: [Item] | |
init() { | |
self.items = [Item(title: "deixar de ser burra")] | |
} | |
} | |
struct Cell: View { | |
@ObservedObject var item: Item | |
var body: some View { | |
Toggle(isOn: $item.done) { | |
Text(item.title) | |
} | |
} | |
} | |
struct ContentView: View { | |
@ObservedObject private var items: Items = Items() | |
var body: some View { | |
List { | |
Section(header: Text("TO DO")) { | |
ForEach(items.items.filter{ $0.done == false }) { item in | |
Cell(item: item) | |
} | |
} | |
Section(header: Text("DONE")) { | |
ForEach(items.items.filter{ $0.done == true }) { item in | |
Cell(item: item) | |
} | |
} | |
} | |
.listStyle(GroupedListStyle()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment