mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
UIApplication notification names are isolated to @MainActor
I believe this is incorrect: FB9801372 (UIApplication.didReceiveMemoryWarningNotification should not be declared @MainActor)
Meanwhile, just use the string version.
A workaround based on a MainActor-isolated task can't work due to conflict between compiler version and minimum iOS target:
#if compiler(>=5.5) && canImport(_Concurrency)
if #available(...) { // Check for availability of concurrency runtime
Task { @MainActor [weak self] in
NotificationCenter.default.addObserver(..., name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
}
} else {
// IMPOSSIBLE CASE: No access to Task, no access to notification names
}
#else
NotificationCenter.default.addObserver(..., name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
#endif
This commit is contained in:
1 parent
b2985b77c4
commit
33d9ca0e97
2 files changed
+14
-4
No files matched your search
@@ -183,15 +183,20 @@ 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: UIApplication.didReceiveMemoryWarningNotification,
|
||||
name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"),
|
||||
object: nil)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(DatabasePool.applicationDidEnterBackground(_:)),
|
||||
name: UIApplication.didEnterBackgroundNotification,
|
||||
name: NSNotification.Name(rawValue: "UIApplicationDidEnterBackgroundNotification"),
|
||||
object: nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,15 +92,20 @@ 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: UIApplication.didReceiveMemoryWarningNotification,
|
||||
name: NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification"),
|
||||
object: nil)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)),
|
||||
name: UIApplication.didEnterBackgroundNotification,
|
||||
name: NSNotification.Name(rawValue: "UIApplicationDidEnterBackgroundNotification"),
|
||||
object: nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user