Skip to content
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

fix: do not force cast KVO values #359

Merged
merged 1 commit into from
Feb 19, 2024
Merged

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Feb 15, 2024

📜 Description

Do not use force casting in swift - replaced with optional casting and guard statements.

💡 Motivation and Context

In sentry one of library user seen this:

Thread 0 - (TH_STATE_WAITING)
0  Trusted +0x5746c0        Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value (KeyboardMovementObserver.swift:109:65)
1  Trusted +0x5705cc        KeyboardMovementObserver.observeValue(forKeyPath:of:change:context:) (<compiler-generated>)
2  Foundation +0x99e54      _NSKeyValueNotifyObserver
3  Foundation +0x99cf0      _NSKeyValueDidChange
4  Foundation +0x99b20      -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:]
5  Foundation +0x99850      -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:]
6  Foundation +0x12cb94     __NSSetPointValueAndNotify
7  UIKitCore +0x615f4       -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:]
8  UIKitCore +0x60e44       -[UIView(Geometry) _resizeWithOldSuperviewSize:]
9  CoreFoundation +0x353f0  ___NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__

It was very random crash, but still - it's not a good practice to use force casting and as a prof -> it produces a crash in certain cases.

So in this PR I replaced it with more safe operators.

Closes #93 (comment)

📢 Changelog

iOS

  • do not force cast KVO values

🤔 How Has This Been Tested?

There is no way to test whether crashes are gone or not, but I think they should gone (in worst case we will have a new stacktrace).

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🍎 iOS iOS specific 🎯 crash Library triggers a crash of the app labels Feb 15, 2024
@kirillzyusko kirillzyusko self-assigned this Feb 15, 2024
@kirillzyusko kirillzyusko mentioned this pull request Feb 15, 2024
Copy link
Contributor

📊 Package size report

Current size Target Size Difference
109835 bytes 109837 bytes -2 bytes 📉

@kirillzyusko kirillzyusko added 👆 interactive keyboard Anything related to interactive keyboard dismissing focused input 📝 Anything about focused input functionality labels Feb 15, 2024
@kirillzyusko kirillzyusko marked this pull request as ready for review February 18, 2024 20:51
@kirillzyusko kirillzyusko merged commit 031c64c into main Feb 19, 2024
10 checks passed
@kirillzyusko kirillzyusko deleted the fix/93-do-not-use-force-cast branch February 19, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎯 crash Library triggers a crash of the app focused input 📝 Anything about focused input functionality 👆 interactive keyboard Anything related to interactive keyboard dismissing 🍎 iOS iOS specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes on iOS 15
1 participant