Simplify iOS memory management, assuming swift(>=4.2)

This commit is contained in:
Gwendal Roué committed 2019-02-07 08:25:31 +01:00
1 parent b6f79f176c
commit 3eb36768c6
2 files changed
+22 -26

No files matched your search

+11 -13
View File
@@ -177,13 +177,16 @@ extension DatabasePool {
public func setupMemoryManagement(in application: UIApplication) {
self.application = application
let center = NotificationCenter.default
#if swift(>=4.2)
center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
#else
center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil)
#endif
center.addObserver(
self,
selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)),
name: UIApplication.didReceiveMemoryWarningNotification,
object: nil)
center.addObserver(
self,
selector: #selector(DatabasePool.applicationDidEnterBackground(_:)),
name: UIApplication.didReceiveMemoryWarningNotification,
object: nil)
}
@objc private func applicationDidEnterBackground(_ notification: NSNotification) {
@@ -192,12 +195,7 @@ extension DatabasePool {
}
let task: UIBackgroundTaskIdentifier = application.beginBackgroundTask(expirationHandler: nil)
#if swift(>=4.2)
let taskIsInvalid = task == UIBackgroundTaskIdentifier.invalid
#else
let taskIsInvalid = task == UIBackgroundTaskInvalid
#endif
if taskIsInvalid {
if task == .invalid {
// Perform releaseMemory() synchronously.
releaseMemory()
} else {
+11 -13
View File
@@ -94,13 +94,16 @@ extension DatabaseQueue {
public func setupMemoryManagement(in application: UIApplication) {
self.application = application
let center = NotificationCenter.default
#if swift(>=4.2)
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
#else
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil)
#endif
center.addObserver(
self,
selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)),
name: UIApplication.didReceiveMemoryWarningNotification,
object: nil)
center.addObserver(
self,
selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)),
name: UIApplication.didEnterBackgroundNotification,
object: nil)
}
@objc private func applicationDidEnterBackground(_ notification: NSNotification) {
@@ -109,12 +112,7 @@ extension DatabaseQueue {
}
let task: UIBackgroundTaskIdentifier = application.beginBackgroundTask(expirationHandler: nil)
#if swift(>=4.2)
let taskIsInvalid = task == UIBackgroundTaskIdentifier.invalid
#else
let taskIsInvalid = task == UIBackgroundTaskInvalid
#endif
if taskIsInvalid {
if task == .invalid {
// Perform releaseMemory() synchronously.
releaseMemory()
} else {