SaveController.swift 667 B

12345678910111213141516171819202122232425262728
  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: "Weekly Tracker \(date).yml")
  11. }
  12. static func save(_ items: [Project], toUrl: URL) {
  13. save(data: Data(items.map({ $0.yaml() }).joined().utf8), toUrl: toUrl)
  14. }
  15. static func save(data: Data, toUrl: URL) {
  16. do {
  17. try data.write(to: toUrl, options: [.atomic, .completeFileProtection])
  18. let input = try String(contentsOf: toUrl, encoding: .utf8)
  19. print(input)
  20. } catch {
  21. print(error.localizedDescription)
  22. }
  23. }
  24. }