Skip to content

RSSelectionMenu crashes if app uses UIKit Scene #122

@dme8a8

Description

@dme8a8

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

  1. Create a new iOS app using the default Xcode template with SceneDelegate enabled (multi-scene / UIScene lifecycle).
  2. Present RSSelectionMenu (e.g. from a pushed view controller or modal).
  3. 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  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions