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?.window is nil under 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
Crash in UIKit Scene-based apps (UIApplication.shared.delegate?.window is nil)
Summary
RSSelectionMenuControllercan crash in scene-based iOS apps because it force-unwrapsUIApplication.shared.delegate?.window(or derived values). In multi-window (UIScene) setups, the app delegate typically does not own a window (SceneDelegate/UIWindowScenedoes), soUIApplication.shared.delegate?.windowis oftennil.This results in a runtime crash (
Swift runtime failure: unexpectedly found nil while unwrapping an Optional value).Affected area
RSSelectionMenuControlleraround line ~227 (exact line may vary by version), where window bounds/orientation are derived from:UIApplication.shared.delegate?.windowwindow??.boundstableView!usageSteps to reproduce
RSSelectionMenu(e.g. from a pushed view controller or modal).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 valueUIApplication.shared.delegate?.windowisnilunder scenes.Environment
Root cause
In scene-based apps, windows are owned by
UIWindowScene/SceneDelegate, notUIApplicationDelegate. Therefore: