-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer KVO for app storage observation #3487
Conversation
} | ||
let willEnterForeground: (any NSObjectProtocol)? | ||
if let willEnterForegroundNotificationName { | ||
willEnterForeground = NotificationCenter.default.addObserver( | ||
forName: willEnterForegroundNotificationName, | ||
object: nil, | ||
queue: nil | ||
queue: .main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this forces a thread hop, which means we should avoid the crash even on invalid KVO keys, but we could also do an explicit dispatch if we're not confident here.
@@ -60,22 +60,6 @@ extension AppStorageKeyPathKey: PersistenceKey, Hashable { | |||
observer.invalidate() | |||
} | |||
} | |||
|
|||
private class Observer: NSObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This observer wasn't used anymore.
warm-simulator: | ||
@test "$(PLATFORM_ID)" != "" \ | ||
&& xcrun simctl boot $(PLATFORM_ID) \ | ||
&& open -a Simulator --args -CurrentDeviceUDID $(PLATFORM_ID) \ | ||
|| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to see if we can reduce CI flakiness by warming the simulators.
@stephencelis Looks like this also fixes this issue. |
Observing the firehose notification from Notification Center is not only less performant, but it can cause crashes in SwiftUI if a notification is posted during a view body update, which can occur in certain situations.
Instead, we will prefer KVO unless we detect an invalid key, such as one that contains a
.
or is prefixed with an@
.Fixes #3311.