-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Crash in UIKit Scene-based apps (UIApplication.shared.delegate?.window is nil)
Summary
RSSelectionMenuController can crash in scene-based iOS apps because it force-unwraps UIApplication.shared.delegate?.window (or derived values). In multi-window (UIScene) setups, the app delegate typically does not own a window (SceneDelegate / UIWindowScene does), so UIApplication.shared.delegate?.window is often nil.
This results in a runtime crash (Swift runtime failure: unexpectedly found nil while unwrapping an Optional value).
Affected area
RSSelectionMenuController around line ~227 (exact line may vary by version), where window bounds/orientation are derived from:
UIApplication.shared.delegate?.window- force-unwrapped
window??.bounds - possibly other force unwraps such as
tableView!usage
Steps to reproduce
- Create a new iOS app using the default Xcode template with SceneDelegate enabled (multi-scene / UIScene lifecycle).
- Present
RSSelectionMenu(e.g. from a pushed view controller or modal). - Trigger the code path that computes layout using
UIApplication.shared.delegate?.window(e.g. showing the menu / background overlay).
Expected behavior
Menu presents correctly without crashes in scene-based apps.
Actual behavior
App crashes with something like:
Thread 1: Swift runtime failure: unexpectedly found nil while unwrapping an Optional value- because
UIApplication.shared.delegate?.windowisnilunder scenes.
Environment
- iOS: 13+ (UIScene lifecycle)
- App lifecycle: SceneDelegate / UIWindowScene
- Library: RSSelectionMenu (version 7.1.3)
- Xcode: 26.2
Root cause
In scene-based apps, windows are owned by UIWindowScene / SceneDelegate, not UIApplicationDelegate. Therefore:
UIApplication.shared.delegate?.window