Sfoglia il codice sorgente

fix: properly re-attach parents when decoding

Sam Jaffe 2 settimane fa
parent
commit
a87d01a2f6
2 ha cambiato i file con 3 aggiunte e 0 eliminazioni
  1. 1 0
      Todos/Model/Project.swift
  2. 2 0
      Todos/Model/Task.swift

+ 1 - 0
Todos/Model/Project.swift

@@ -39,6 +39,7 @@ final class Project: Codable, Ordered {
     category = try container.decode(String.self, forKey: .category)
     name = try container.decode(String.self, forKey: .name)
     tasks = try container.decode([Task].self, forKey: .tasks)
+    tasks.forEach({ $0.project = self })
   }
 
   func encode(to encoder: any Encoder) throws {

+ 2 - 0
Todos/Model/Task.swift

@@ -136,6 +136,8 @@ final class Task: Codable, Ordered {
     subtasks = try container.decode([SubTask].self, forKey: .subtasks)
     notes = try container.decode(String.self, forKey: .notes)
     status = try container.decode(Status.self, forKey: .status)
+    tags.forEach({ $0.task = self })
+    subtasks.forEach({ $0.task = self })
   }
 
   func encode(to encoder: any Encoder) throws {