|
@@ -8,15 +8,19 @@
|
|
|
import Foundation
|
|
import Foundation
|
|
|
|
|
|
|
|
final class SaveController {
|
|
final class SaveController {
|
|
|
- static func filename(date: String) -> URL {
|
|
|
|
|
|
|
+ private func filename(date: String) -> URL {
|
|
|
URL.documentsDirectory.appending(path: "Weekly Tracker \(date).yml")
|
|
URL.documentsDirectory.appending(path: "Weekly Tracker \(date).yml")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static func save(_ items: [Project], toUrl: URL) {
|
|
|
|
|
|
|
+ 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)
|
|
save(data: Data(items.map({ $0.yaml() }).joined().utf8), toUrl: toUrl)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static func save(data: Data, toUrl: URL) {
|
|
|
|
|
|
|
+ func save(data: Data, toUrl: URL) {
|
|
|
do {
|
|
do {
|
|
|
try data.write(to: toUrl, options: [.atomic, .completeFileProtection])
|
|
try data.write(to: toUrl, options: [.atomic, .completeFileProtection])
|
|
|
let input = try String(contentsOf: toUrl, encoding: .utf8)
|
|
let input = try String(contentsOf: toUrl, encoding: .utf8)
|