Slide 49
Slide 49 text
49
એݴత6*ͷঢ়ଶཧΞʔΩςΫνϟͷྺ࢙5IF$PNQPTBCMF"SDIJUFDUVSF
w 5$"ͷίʔυ
enum ToDoAction: Equatable {
case append
case toggle(UUID)
}
let toDoReducer = Reducer<
ToDoState,
ToDoAction,
ToDoEnvironment> { state, action, environment in
switch action {
case .append:
state.tasks += [Task(title: "Ճ", done: false)]
return .none
case let .toggle(id):
state.tasks = state.tasks.map { task in
guard task.id == id else {
return task
}
var newTask = task
newTask.done = !newTask.done
return newTask
}
return .none
}
}
struct ToDoState : Equatable {
var tasks: [Task] = []
var completed: [Task] {
get{
return tasks.filter { $0.done }
}
}
var unCompleted: [Task] {
get{
return tasks.filter { !$0.done }
}
}
}
3FEVDFS͕BDUJPOΛड͚ͯ4UBUFΛߋ৽