Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. //
  2. // SceneDelegate.swift
  3. // BankUI
  4. //
  5. // Created by KORNEEV Viktor on 20/12/2019.
  6. // Copyright © 2019 Korneev Viktor. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import RealmSwift
  11.  
  12. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  13.  
  14. var window: UIWindow?
  15.  
  16. func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  17. UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17, weight: .semibold)]
  18.  
  19. guard let windowScene = (scene as? UIWindowScene) else { return }
  20. let window = UIWindow(windowScene: windowScene)
  21.  
  22. if UserDefaults.standard.value(forKey: "BankUI") != nil {
  23. let loginVC = LoginVC()
  24. window.rootViewController = loginVC
  25. } else {
  26. let registrationVC = RegistrationMenu()
  27. window.rootViewController = registrationVC
  28. }
  29.  
  30. self.window = window
  31. window.makeKeyAndVisible()
  32.  
  33. //Получаем путь к папке на данном ПК, где хранится БД Realm
  34. print("База данных Realm находится в дирректории - \(Realm.Configuration.defaultConfiguration.fileURL!)")
  35.  
  36. setRealmName(realmName: "Transactions")
  37. }
  38.  
  39. ///Устанавливает имя для таблицы в БД Realm
  40. ///
  41. /// - Parameters:
  42. /// - realmName: Имя для таблицы Realm
  43. func setRealmName(realmName: String) {
  44. var config = Realm.Configuration()
  45.  
  46. //Используем путь к дирректории где лежит файл .realm по умолчанию, но заменяем имя на то которое нам нужно
  47. config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("\(realmName).realm")
  48.  
  49. //Устанавливаем созданную нами конфигурацию для БД Realm
  50. Realm.Configuration.defaultConfiguration = config
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement