-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwiftLeeAggregatorApp.swift
executable file
·38 lines (33 loc) · 1.29 KB
/
SwiftLeeAggregatorApp.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// SwiftLeeAggregatorApp.swift
// SwiftLeeAggregator
//
// Created by Peter van den Hamer on 04/06/2022.
//
import SwiftUI
import CoreData
@main
struct SwiftLeeAggregatorApp: App {
// https://www.hackingwithswift.com/quick-start/swiftui/how-to-configure-core-data-to-work-with-swiftui
@Environment(\.scenePhase) var scenePhase
private let persistenceController = PersistenceController.shared
private let swiftLeeDebugMode = false
init() {
let viewContext = persistenceController.container.viewContext
// SwiftLee sometimes updates an article. The title and shortURL stay the same but publication date changes
viewContext.mergePolicy = NSMergePolicy.mergeByPropertyStoreTrump // was .overwrite
if swiftLeeDebugMode {
print("Running with debug in SwilftLeeAggregatorApp.swift set to \(swiftLeeDebugMode)")
}
}
var body: some Scene {
WindowGroup {
PostListView(swiftLeeDebugModePayloadString: swiftLeeDebugMode ?
hardcodedJsonString : nil)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
.onChange(of: scenePhase) { _, _ in
persistenceController.save() // when app moves to background
}
}
}