Avatar ·

How to sort an array of custom objects by property value in Swift?

Hello everyone! I'm new to Swift and writing a small task management app. I have a `Task` struct with fields `title`, `priority` (Int), and `dueDate` (Date). I created an array of such tasks: ```swift struct Task { let title: String var priority: Int var dueDate: Date } var tasks = [ Task(title: "Buy groceries", priority: 3, dueDate: Date()), Task(title: "Make report", priority: 1, dueDate: Date().addingTimeInterval(86400)), Task(title: "Call client", priority: 2, dueDate: Date().addingTimeInterval(172800)) ] ``` Now I want to sort this array by priority (from highest to lowest), and then by date (from earliest to latest). I tried using `sorted(by:)` with a closure, but I get type errors or incorrect results.