From 33a039717ce980fd6df8ca9e846fd7fdf3644658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Rou=C3=A9?= Date: Thu, 28 Jul 2022 13:16:06 +0200 Subject: [PATCH] Refer to UIApplication notifications by their names It looks like FB9801372 was fixed --- GRDB/Core/DatabasePool.swift | 9 ++------- GRDB/Core/DatabaseQueue.swift | 9 ++------- Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift | 6 +++--- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index 4b98d3fcb..bf4b986fe 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -214,20 +214,15 @@ extension DatabasePool { /// as much memory as possible. private func setupMemoryManagement() { let center = NotificationCenter.default - - // Use raw notification names because of - // FB9801372 (UIApplication.didReceiveMemoryWarningNotification should not be declared @MainActor) - // TODO: Reuse UIApplication.didReceiveMemoryWarningNotification when possible. - // TODO: Reuse UIApplication.didEnterBackgroundNotification when possible. center.addObserver( self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), - name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"), + name: UIApplication.didReceiveMemoryWarningNotification, object: nil) center.addObserver( self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), - name: NSNotification.Name(rawValue: "UIApplicationDidEnterBackgroundNotification"), + name: UIApplication.didEnterBackgroundNotification, object: nil) } diff --git a/GRDB/Core/DatabaseQueue.swift b/GRDB/Core/DatabaseQueue.swift index 9e3156263..dbcf000f7 100644 --- a/GRDB/Core/DatabaseQueue.swift +++ b/GRDB/Core/DatabaseQueue.swift @@ -93,20 +93,15 @@ extension DatabaseQueue { /// as much memory as possible. private func setupMemoryManagement() { let center = NotificationCenter.default - - // Use raw notification names because of - // FB9801372 (UIApplication.didReceiveMemoryWarningNotification should not be declared @MainActor) - // TODO: Reuse UIApplication.didReceiveMemoryWarningNotification when possible. - // TODO: Reuse UIApplication.didEnterBackgroundNotification when possible. center.addObserver( self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), - name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"), + name: UIApplication.didReceiveMemoryWarningNotification, object: nil) center.addObserver( self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), - name: NSNotification.Name(rawValue: "UIApplicationDidEnterBackgroundNotification"), + name: UIApplication.didEnterBackgroundNotification, object: nil) } diff --git a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift index d12e73776..6e338372a 100644 --- a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift @@ -59,7 +59,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { // Simulate memory warning. NotificationCenter.default.post( - name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"), + name: UIApplication.didReceiveMemoryWarningNotification, object: nil) // Postcondition: reader connection was closed @@ -87,7 +87,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { // Simulate memory warning. NotificationCenter.default.post( - name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"), + name: UIApplication.didReceiveMemoryWarningNotification, object: nil) // Postcondition: no reader connection was closed @@ -108,7 +108,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { // Simulate memory warning. NotificationCenter.default.post( - name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"), + name: UIApplication.didReceiveMemoryWarningNotification, object: nil) // Make sure we can read