diff --git a/src/appkit/toolbar/class.rs b/src/appkit/toolbar/class.rs index dba9107b..60ff60da 100644 --- a/src/appkit/toolbar/class.rs +++ b/src/appkit/toolbar/class.rs @@ -57,7 +57,7 @@ extern "C" fn selectable_item_identifiers(this: &Object, _: /// Objective-C runtime needs. extern "C" fn item_for_identifier(this: &Object, _: Sel, _: id, identifier: id, _: Bool) -> id { let toolbar = load::(this, TOOLBAR_PTR); - let identifier = NSString::from_retained(identifier); + let identifier = NSString::retain(identifier); let item = toolbar.item_for(identifier.to_str()); unsafe { msg_send![&*item.objc, self] } diff --git a/src/foundation/array.rs b/src/foundation/array.rs index 7efc302f..ec03a1b5 100644 --- a/src/foundation/array.rs +++ b/src/foundation/array.rs @@ -31,12 +31,6 @@ impl NSArray { NSArray(unsafe { Id::retain(array).unwrap() }) } - /// In some cases, we're vended an `NSArray` by the system, and it's ideal to not retain that. - /// This handles that edge case. - pub fn from_retained(array: id) -> Self { - NSArray(unsafe { Id::new(array).unwrap() }) - } - /// Returns the `count` (`len()` equivalent) for the backing `NSArray`. pub fn count(&self) -> usize { unsafe { msg_send![&*self.0, count] } diff --git a/src/foundation/data.rs b/src/foundation/data.rs index 1d7800d6..48bd145b 100644 --- a/src/foundation/data.rs +++ b/src/foundation/data.rs @@ -77,12 +77,6 @@ impl NSData { NSData(unsafe { Id::retain(data).unwrap() }) } - /// If we're vended an NSData from a method (e.g, a push notification token) we might want to - /// wrap it while we figure out what to do with it. This does that. - pub fn from_retained(data: id) -> Self { - NSData(unsafe { Id::new(data).unwrap() }) - } - /// A helper method for determining if a given `NSObject` is an `NSData`. pub fn is(obj: id) -> bool { let result: BOOL = unsafe { msg_send![obj, isKindOfClass: class!(NSData)] }; diff --git a/src/foundation/string.rs b/src/foundation/string.rs index d7e8a172..d6adbbe8 100644 --- a/src/foundation/string.rs +++ b/src/foundation/string.rs @@ -66,10 +66,9 @@ impl<'a> NSString<'a> { } } - /// In some cases, we want to wrap a system-provided NSString without retaining it. - pub fn from_retained(object: id) -> Self { - NSString { - objc: unsafe { Id::new(object).unwrap() }, + pub fn from_id(objc: Id) -> Self { + Self { + objc, phantom: PhantomData } } diff --git a/src/foundation/urls/mod.rs b/src/foundation/urls/mod.rs index 56706084..103143f3 100644 --- a/src/foundation/urls/mod.rs +++ b/src/foundation/urls/mod.rs @@ -45,14 +45,6 @@ impl<'a> NSURL<'a> { } } - /// In some cases, we want to wrap a system-provided NSURL without retaining it. - pub fn from_retained(object: id) -> Self { - NSURL { - objc: unsafe { Id::new(object).unwrap() }, - phantom: PhantomData - } - } - /// Creates and returns a URL object by calling through to `[NSURL URLWithString]`. pub fn with_str(url: &str) -> Self { let url = NSString::new(url); diff --git a/src/text/attributed_string.rs b/src/text/attributed_string.rs index 092e4eda..e5b63666 100644 --- a/src/text/attributed_string.rs +++ b/src/text/attributed_string.rs @@ -74,7 +74,7 @@ impl AttributedString { impl fmt::Display for AttributedString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let string = NSString::from_retained(unsafe { msg_send![&*self.0, string] }); + let string = NSString::from_id(unsafe { msg_send_id![&*self.0, string] }); write!(f, "{}", string.to_str()) } @@ -82,7 +82,7 @@ impl fmt::Display for AttributedString { impl fmt::Debug for AttributedString { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let string = NSString::from_retained(unsafe { msg_send![&*self.0, string] }); + let string = NSString::from_id(unsafe { msg_send_id![&*self.0, string] }); f.debug_struct("AttributedString").field("text", &string.to_str()).finish() } diff --git a/src/uikit/scene/session.rs b/src/uikit/scene/session.rs index bb0aec1d..25a6740f 100644 --- a/src/uikit/scene/session.rs +++ b/src/uikit/scene/session.rs @@ -14,6 +14,6 @@ impl SceneSession { } pub fn role(&self) -> SessionRole { - NSString::from_retained(unsafe { msg_send![&*self.0, role] }).into() + NSString::from_id(unsafe { msg_send_id![&*self.0, role] }).into() } } diff --git a/src/webview/class.rs b/src/webview/class.rs index ef102292..1cc326b6 100644 --- a/src/webview/class.rs +++ b/src/webview/class.rs @@ -10,7 +10,7 @@ use block::Block; use objc::declare::ClassDecl; use objc::runtime::{Bool, Class, Object, Sel}; -use objc::{class, msg_send, sel}; +use objc::{class, msg_send, msg_send_id, sel}; use crate::foundation::{id, load_or_register_class, nil, NSArray, NSInteger, NSString}; use crate::webview::actions::{NavigationAction, NavigationResponse}; @@ -48,8 +48,8 @@ extern "C" fn on_message(this: &Object, _: Sel, _: id, scrip let delegate = load::(this, WEBVIEW_DELEGATE_PTR); unsafe { - let name = NSString::from_retained(msg_send![script_message, name]); - let body = NSString::retain(msg_send![script_message, body]); + let name = NSString::from_id(msg_send_id![script_message, name]); + let body = NSString::from_id(msg_send_id![script_message, body]); delegate.on_message(name.to_str(), body.to_str()); } } @@ -62,7 +62,7 @@ extern "C" fn start_url_scheme_task(this: &Object, _: Sel, _ let request: id = msg_send![task, request]; let url: id = msg_send![request, URL]; - let uri = NSString::from_retained(msg_send![url, absoluteString]); + let uri = NSString::from_id(msg_send_id![url, absoluteString]); let uri_str = uri.to_str(); if let Some(content) = delegate.on_custom_protocol_request(uri_str) { @@ -152,7 +152,7 @@ extern "C" fn handle_download(this: &Object, _: Sel, downloa let delegate = load::(this, WEBVIEW_DELEGATE_PTR); let handler = handler as *const Block<(objc::runtime::Bool, id), ()>; - let filename = NSString::from_retained(suggested_filename); + let filename = NSString::retain(suggested_filename); delegate.run_save_panel(filename.to_str(), move |can_overwrite, path| unsafe { if path.is_none() {