SaveController.swift 587 B

12345678910111213141516171819202122232425
  1. //
  2. // SaveController.swift
  3. // Todos
  4. //
  5. // Created by Sam Jaffe on 3/1/26.
  6. //
  7. import Foundation
  8. final class SaveController {
  9. static func filename(date: String) -> URL {
  10. URL.documentsDirectory.appending(path: "Todo \(date).yaml")
  11. }
  12. static func save(_ items: [Category], to: URL) {
  13. let data = Data(items.map({ $0.yaml() }).joined().utf8)
  14. do {
  15. try data.write(to: to, options: [.atomic, .completeFileProtection])
  16. let input = try String(contentsOf: to, encoding: .utf8)
  17. print(input)
  18. } catch {
  19. print(error.localizedDescription)
  20. }
  21. }
  22. }