From 8c1cd33e6bc5d8bf5bab1b4df66f18e1d9ed3ea2 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 28 Jul 2020 11:15:20 +0200 Subject: [PATCH] Extracted setupBankingUi() --- .../BankingiOSApp/SceneDelegate.swift | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift b/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift index 63490fb2..22005f7e 100644 --- a/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift +++ b/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift @@ -1,5 +1,6 @@ import UIKit import SwiftUI +import CoreData import BankingUiSwift @@ -17,19 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let appDelegate = UIApplication.shared.delegate as! AppDelegate let context = appDelegate.persistentContainer.viewContext - - let appDataFolder = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, .userDomainMask, true).first - ?? Bundle.main.resourceURL?.absoluteString ?? "" - - let persistence = CoreDataBankingPersistence(context: context) - - let dataFolder = URL(fileURLWithPath: "data", isDirectory: true, relativeTo: URL(fileURLWithPath: appDataFolder)) - - let presenter = BankingPresenterSwift(dataFolder: dataFolder, router: SwiftUiRouter(), webClient: UrlSessionWebClient(), persistence: persistence, remitteeSearcher: persistence, asyncRunner: DispatchQueueAsyncRunner()) - - DependencyInjector.register(dependency: persistence) - DependencyInjector.register(dependency: presenter) - + setupBankingUi(context: context) // Create the SwiftUI view and set the context as the value for the managedObjectContext environment keyPath. // Add `@Environment(\.managedObjectContext)` in the views that will need the context. @@ -44,6 +33,21 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { window.makeKeyAndVisible() } } + + private func setupBankingUi(context: NSManagedObjectContext) { + let appDataFolder = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, .userDomainMask, true).first + ?? Bundle.main.resourceURL?.absoluteString ?? "" + + let persistence = CoreDataBankingPersistence(context: context) + + let dataFolder = URL(fileURLWithPath: "data", isDirectory: true, relativeTo: URL(fileURLWithPath: appDataFolder)) + + let presenter = BankingPresenterSwift(dataFolder: dataFolder, router: SwiftUiRouter(), webClient: UrlSessionWebClient(), persistence: persistence, remitteeSearcher: persistence, serializer: JsonEncoderSerializer(), asyncRunner: DispatchQueueAsyncRunner()) + + DependencyInjector.register(dependency: persistence) + DependencyInjector.register(dependency: presenter) + } + func sceneDidDisconnect(_ scene: UIScene) { // Called as the scene is being released by the system.