Skip to content

Commit aa1ca63

Browse files
authored
m: Deprecate UiKitWindowHandle::ui_view_controller
This can be retrieved from the UIView itself, and is hence unnecessary information for us to carry around. Besides, since it's optional, users that want to get the view controller has to do the searching logic anyways.
1 parent 29ff5aa commit aa1ca63

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Improve documentation on AppKit and UIKit handles.
6+
* Deprecated `UiKitWindowHandle::ui_view_controller`, retrieve this from the UIView's responder chain instead.
67

78
## 0.6.2 (2024-05-17)
89

src/uikit.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ pub struct UiKitWindowHandle {
8888
/// A pointer to an `UIView` object.
8989
pub ui_view: NonNull<c_void>,
9090
/// A pointer to an `UIViewController` object, if the view has one.
91+
///
92+
/// This is deprecated, the controller should be retrieved by traversing the `UIView`'s\
93+
/// responder chain instead:
94+
///
95+
/// ```ignore
96+
/// use objc2::rc::Retained;
97+
/// use objc2_ui_kit::{UIResponder, UIView, UIViewController};
98+
///
99+
/// let view: Retained<UIView> = ...;
100+
///
101+
/// let mut current_responder: Retained<UIResponder> = view.into_super();
102+
/// let mut found_controller = None;
103+
/// while let Some(responder) = unsafe { current_responder.nextResponder() } {
104+
/// match responder.downcast::<UIViewController>() {
105+
/// Ok(controller) => {
106+
/// found_controller = Some(controller);
107+
/// break;
108+
/// }
109+
/// // Search next.
110+
/// Err(responder) => current_responder = responder,
111+
/// }
112+
/// }
113+
///
114+
/// // Use found_controller here.
115+
/// ```
116+
#[deprecated = "retrieve the view controller from the UIView's responder chain instead"]
91117
pub ui_view_controller: Option<NonNull<c_void>>,
92118
}
93119

@@ -107,11 +133,10 @@ impl UiKitWindowHandle {
107133
///
108134
/// let ui_view: Retained<UIView> = ...;
109135
/// let ui_view: NonNull<UIView> = NonNull::from(&*ui_view);
110-
/// let mut handle = UiKitWindowHandle::new(ui_view.cast());
111-
/// // Optionally, set the view controller too.
112-
/// handle.ui_view_controller = None;
136+
/// let handle = UiKitWindowHandle::new(ui_view.cast());
113137
/// ```
114138
pub fn new(ui_view: NonNull<c_void>) -> Self {
139+
#[allow(deprecated)]
115140
Self {
116141
ui_view,
117142
ui_view_controller: None,

0 commit comments

Comments
 (0)