-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDelegate.swift
45 lines (34 loc) · 1.38 KB
/
AppDelegate.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
39
40
41
42
43
44
45
//
// AppDelegate.swift
// VirtualTourist
//
// Created by Max Boguslavskiy on 02/05/2018.
// Copyright © 2018 Max Boguslavskiy. All rights reserved.
//
import UIKit
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var locationManager: CLLocationManager?
let dataController = DataController(modelName: "VirtualTourist")
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
dataController.load()
let navigationController = window?.rootViewController as! UINavigationController
let travelLocationsViewController = navigationController.topViewController as! TravelLocationsMapViewController
travelLocationsViewController.dataController = dataController
locationManager = CLLocationManager()
locationManager?.requestWhenInUseAuthorization()
return true
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
saveViewContext()
}
func saveViewContext() {
try? dataController.viewContext.save()
}
}