Good evening everyone.
Good afternoon.
I'm experimenting with enumerations, and I can't figure out how to get something out of it using a switch or if-else
What the hell is happening...
let tasks: [Task] = [
Task(title: "See lesson: Spinner Using SwiftUI", typeTask: .regularTask(RegularTask())),
Task(title: "Read about Ad hoc install app", typeTask: .importantTask(ImportantTask(important: .medium))),
Task(title: "See lesson @Composible Kotlin", typeTask: .regularTask(RegularTask())),
Task(title: "See WWDC 2024", typeTask: .importantTask(ImportantTask(important: .low))),
Task(title: "Read about ExperimentalMaterial3Api Kotlin", typeTask: .importantTask(ImportantTask(important: .medium))),
Task(title: "Finish the test PlantUML", typeTask: .importantTask(ImportantTask(important: .high))),
Task(title: "Finish the test PlantUML", typeTask: .regularTask(RegularTask()))
]
for index in tasks {
print(index.typeTask)
if let task == index.typeTask as? RegularTask {
print("1")
}
}
// OR
switch index.typeTask {
case .regularTask(_):
print(index.typeTask)
case .importantTask(_):
print(index.typeTask)
}
}
import Foundation
enum TypeTask {
case regularTask(RegularTask)
case importantTask(ImportantTask)
}
struct Task {
var title: String
var completed: Status = .notStarted
var typeTask: TypeTask
enum Status {
case notStarted
case completed
case canceled
case paused
}
}
struct RegularTask { }
struct ImportantTask {
private let date = Date()
var important: TaskPriority
var deadLine: Date {
switch important {
case .low:
return calculateDate(3)
case .medium:
return calculateDate(2)
case .high:
return calculateDate(1)
}
}
enum TaskPriority: Int {
case low
case medium
case high
}
private func calculateDate(_ value: Int) -> Date {
guard let data = Calendar.current.date(byAdding: .day, value: value, to: Date()) else {
return Date()
}
return data
}
}