I have a structure TodoItem
struct TodoItem: Codable, Hashable, Identifiable {
var id: UUID = UUID()
var item: String
var done: Bool = false
}
And I have an array of them, and I’d like to find out a way to calculate(in a array
) how many are done; that is, myArray.count / itemsDone
.count
is easy, itemsDone
can be achieved like this:
extension Array where Element == TodoItem {
var itemsDone: Double {
var done: Double = 0
for i in self {
if i.done { done += 1 }
}
return done
}
}
but it didn’t.
struct ContentView: View {
@State var todos: [TodoItem]
…
ProgressView(value: todos.itemsDone / todos.count) // Error
My Playground won’t let me copy the error(no idea why) and my family’s iPad is in Chinese so one is Chinese. I’ll try it on Xcode and see if I can find out more. will update with the error.
EDiT nor will this work:
ProgressView(value: todos.itemsDone, total: todos.count)