diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index f1c7201f..766677bb 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -209,9 +209,7 @@ impl View { center_x: LayoutAnchorX::center(view), center_y: LayoutAnchorY::center(view), - layer: Layer::wrap(unsafe { - msg_send![view, layer] - }), + layer: Layer::from_id(unsafe { msg_send_id![view, layer] }), objc: ObjcProperty::retain(view), } diff --git a/src/appkit/toolbar/item.rs b/src/appkit/toolbar/item.rs index 6f2a76f5..22428d45 100644 --- a/src/appkit/toolbar/item.rs +++ b/src/appkit/toolbar/item.rs @@ -49,17 +49,6 @@ impl ToolbarItem { } } - pub(crate) fn wrap(item: id) -> Self { - ToolbarItem { - identifier: "".to_string(), - objc: unsafe { Id::new(item).unwrap() }, - button: None, - segmented_control: None, - image: None, - handler: None - } - } - /// Sets the title for this item. pub fn set_title(&mut self, title: &str) { unsafe { diff --git a/src/defaults/mod.rs b/src/defaults/mod.rs index a65eacad..e8fee70c 100644 --- a/src/defaults/mod.rs +++ b/src/defaults/mod.rs @@ -200,7 +200,7 @@ impl UserDefaults { // // For context: https://nshipster.com/type-encodings/ if NSNumber::is(result) { - let number = NSNumber::wrap(result); + let number = NSNumber::retain(result); return match number.objc_type() { "c" => Some(Value::Bool(number.as_bool())), diff --git a/src/foundation/number.rs b/src/foundation/number.rs index fcd2cf36..ce980395 100644 --- a/src/foundation/number.rs +++ b/src/foundation/number.rs @@ -21,12 +21,6 @@ impl NSNumber { NSNumber(unsafe { Id::retain(data).unwrap() }) } - /// If we're vended an NSNumber from a method (e.g, `NSUserDefaults` querying) we might want to - /// wrap it while we figure out what to do with it. This does that. - pub fn wrap(data: id) -> Self { - NSNumber(unsafe { Id::new(data).unwrap() }) - } - /// Constructs a `numberWithBool` instance of `NSNumber` and retains it. pub fn bool(value: bool) -> Self { NSNumber(unsafe { diff --git a/src/image/mod.rs b/src/image/mod.rs index c9561a12..8b567235 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -2,7 +2,7 @@ use core_foundation::base::TCFType; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; -use objc::{msg_send, sel}; +use objc::{msg_send, msg_send_id, sel}; use crate::color::Color; use crate::foundation::{id, nil, NSArray, NSString, NO, YES}; @@ -142,7 +142,7 @@ impl ImageView { #[cfg(feature = "autolayout")] center_y: LayoutAnchorY::center(view), - layer: Layer::wrap(unsafe { msg_send![view, layer] }), + layer: Layer::from_id(unsafe { msg_send_id![view, layer] }), objc: ObjcProperty::retain(view) } diff --git a/src/layer/mod.rs b/src/layer/mod.rs index b61c8d76..c2023825 100644 --- a/src/layer/mod.rs +++ b/src/layer/mod.rs @@ -14,7 +14,9 @@ use core_graphics::base::CGFloat; -use objc::{class, msg_send, sel}; +use objc::rc::{Id, Shared}; +use objc::runtime::Object; +use objc::{class, msg_send, msg_send_id, sel}; use crate::foundation::id; use crate::utils::properties::ObjcProperty; @@ -35,30 +37,26 @@ use crate::utils::properties::ObjcProperty; #[derive(Clone, Debug)] pub struct Layer { /// The underlying layer pointer. - pub objc: ObjcProperty + pub objc: Id } impl Layer { /// Creates a new `CALayer` and retains it. pub fn new() -> Self { Layer { - objc: ObjcProperty::retain(unsafe { msg_send![class!(CALayer), new] }) + objc: unsafe { msg_send_id![class!(CALayer), new] } } } - /// Wraps an existing (already retained) `CALayer`. - pub fn wrap(layer: id) -> Self { - Layer { - objc: ObjcProperty::from_retained(layer) - } + /// Wraps an existing `CALayer`. + pub fn from_id(objc: Id) -> Self { + Layer { objc } } /// Sets the corner radius (for all four corners). /// /// Note that for performance sensitive contexts, you might want to apply a mask instead. pub fn set_corner_radius(&self, radius: f64) { - self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setCornerRadius: radius as CGFloat]; - }); + let _: () = unsafe { msg_send![&self.objc, setCornerRadius: radius as CGFloat] }; } } diff --git a/src/text/label/mod.rs b/src/text/label/mod.rs index 00992602..23cb7de8 100644 --- a/src/text/label/mod.rs +++ b/src/text/label/mod.rs @@ -47,7 +47,7 @@ use core_foundation::base::TCFType; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; -use objc::{msg_send, sel}; +use objc::{msg_send, msg_send_id, sel}; use crate::color::Color; use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NSUInteger, NO, YES}; @@ -251,7 +251,7 @@ impl Label { #[cfg(feature = "autolayout")] center_y: LayoutAnchorY::center(view), - layer: Layer::wrap(unsafe { msg_send![view, layer] }), + layer: Layer::from_id(unsafe { msg_send_id![view, layer] }), objc: ObjcProperty::retain(view) } diff --git a/src/utils/properties.rs b/src/utils/properties.rs index 0671578c..6ccb8eaa 100644 --- a/src/utils/properties.rs +++ b/src/utils/properties.rs @@ -23,11 +23,6 @@ impl ObjcProperty { ObjcProperty(Rc::new(RefCell::new(unsafe { Id::retain(obj).unwrap() }))) } - /// Given an Objective-C object, retains it and wraps it as a `Property`. - pub fn from_retained(obj: id) -> Self { - ObjcProperty(Rc::new(RefCell::new(unsafe { Id::new(obj).unwrap() }))) - } - /// Runs a handler with mutable access for the underlying Objective-C object. /// /// Note that this is mutable access from the Rust side; we make every effort to ensure things are valid diff --git a/src/view/mod.rs b/src/view/mod.rs index 823be6d3..c0e1a334 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -43,7 +43,7 @@ //! For more information on Autolayout, view the module or check out the examples folder. use objc::runtime::{Class, Object}; -use objc::{msg_send, sel}; +use objc::{msg_send, msg_send_id, sel}; use crate::color::Color; use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES}; @@ -217,7 +217,7 @@ impl View { #[cfg(feature = "autolayout")] center_y: LayoutAnchorY::center(view), - layer: Layer::wrap(unsafe { msg_send![view, layer] }), + layer: Layer::from_id(unsafe { msg_send_id![view, layer] }), #[cfg(all(feature = "appkit", target_os = "macos"))] animator: ViewAnimatorProxy::new(view), diff --git a/src/webview/class.rs b/src/webview/class.rs index 1cc326b6..e14dbd3e 100644 --- a/src/webview/class.rs +++ b/src/webview/class.rs @@ -21,7 +21,7 @@ use crate::utils::load; /// Called when an `alert()` from the underlying `WKWebView` is fired. Will call over to your /// `WebViewController`, where you should handle the event. extern "C" fn alert(_: &Object, _: Sel, _: id, _: id, _: id, complete: id) { - //let alert = NSString::wrap(s).to_str(); + //let alert = NSString::retain(s).to_str(); // @TODO: This is technically (I think?) a private method, and there's some other dance that // needs to be done here involving taking the pointer/invoke/casting... but this is fine for diff --git a/src/webview/mod.rs b/src/webview/mod.rs index 0fe574d5..8cbae491 100644 --- a/src/webview/mod.rs +++ b/src/webview/mod.rs @@ -209,7 +209,7 @@ impl WebView { #[cfg(feature = "autolayout")] center_y: LayoutAnchorY::center(view), - layer: Layer::wrap(unsafe { msg_send![view, layer] }), + layer: Layer::from_id(unsafe { msg_send_id![view, layer] }), objc: ObjcProperty::retain(view) }