Created
April 11, 2021 12:55
-
-
Save thatswiftguy/e66ec1e017de2f49b18e391934cf56b3 to your computer and use it in GitHub Desktop.
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
// | |
// TaskViewModel.swift | |
// TaskManager | |
// | |
// Created by Mohammad Yasir on 11/04/21. | |
// | |
import Foundation | |
class TaskViewModel : Identifiable , ObservableObject { | |
@Published var tasks : [Task] = [ | |
Task(name: "Publish An Article", taskName: "@Medium", date: Date(timeIntervalSinceReferenceDate:1619231231.0), priority: .normal), | |
Task(name: "Buy Some Foods", taskName: "BBinstant", date: Date(timeIntervalSinceReferenceDate:1621231231.0), priority: .high), | |
Task(name: "Launch the App", taskName: "App Store", date: Date(), priority: .medium), | |
Task(name: "Walk Around", taskName: "Garden", date: Date(), priority: .normal) | |
] | |
@Published var sortType : SortType = .alphabetical | |
@Published var isPresented = false | |
@Published var searched = "" | |
func addTask(task : Task){ | |
tasks.append(task) | |
} | |
func removeTask(indexAt : IndexSet){ | |
tasks.remove(atOffsets: indexAt) | |
} | |
func sort(){ | |
switch sortType { | |
case .alphabetical : | |
tasks.sort(by: { $0.name < $1.name }) | |
case .date : | |
tasks.sort(by: { $0.date > $1.date }) | |
case .priority : | |
tasks.sort(by: { $0.priority.rawValue > $1.priority.rawValue }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment