Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SceneDelegate.swift
- // BankUI
- //
- // Created by KORNEEV Viktor on 20/12/2019.
- // Copyright © 2019 Korneev Viktor. All rights reserved.
- //
- import UIKit
- import RealmSwift
- class SceneDelegate: UIResponder, UIWindowSceneDelegate {
- var window: UIWindow?
- func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
- UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17, weight: .semibold)]
- guard let windowScene = (scene as? UIWindowScene) else { return }
- let window = UIWindow(windowScene: windowScene)
- if UserDefaults.standard.value(forKey: "BankUI") != nil {
- let loginVC = LoginVC()
- window.rootViewController = loginVC
- } else {
- let registrationVC = RegistrationMenu()
- window.rootViewController = registrationVC
- }
- self.window = window
- window.makeKeyAndVisible()
- //Получаем путь к папке на данном ПК, где хранится БД Realm
- print("База данных Realm находится в дирректории - \(Realm.Configuration.defaultConfiguration.fileURL!)")
- setRealmName(realmName: "Transactions")
- }
- ///Устанавливает имя для таблицы в БД Realm
- ///
- /// - Parameters:
- /// - realmName: Имя для таблицы Realm
- func setRealmName(realmName: String) {
- var config = Realm.Configuration()
- //Используем путь к дирректории где лежит файл .realm по умолчанию, но заменяем имя на то которое нам нужно
- config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("\(realmName).realm")
- //Устанавливаем созданную нами конфигурацию для БД Realm
- Realm.Configuration.defaultConfiguration = config
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement