| 1234567891011121314151617181920212223242526272829303132 |
- //
- // SaveController.swift
- // Todos
- //
- // Created by Sam Jaffe on 3/1/26.
- //
- import Foundation
- final class SaveController {
- private func filename(date: String) -> URL {
- URL.documentsDirectory.appending(path: "Weekly Tracker \(date).yml")
- }
- func save(_ items: [Project], onDate: String) {
- save(items, toUrl: filename(date: onDate))
- }
- func save(_ items: [Project], toUrl: URL) {
- save(data: Data(items.map({ $0.yaml() }).joined().utf8), toUrl: toUrl)
- }
- func save(data: Data, toUrl: URL) {
- do {
- try data.write(to: toUrl, options: [.atomic, .completeFileProtection])
- let input = try String(contentsOf: toUrl, encoding: .utf8)
- print(input)
- } catch {
- print(error.localizedDescription)
- }
- }
- }
|