Struct NSVisualEffectViewTagged

Source
#[repr(C)]
pub struct NSVisualEffectViewTagged { /* private fields */ }
Expand description

A custom NSVisualEffectView subclass that overrides the tag method to provide a custom tag, to later identify the view

Implementations§

Source§

impl NSVisualEffectViewTagged

Source

pub unsafe fn initWithFrame( this: Allocated<Self>, frame_rect: NSRect, tag: NSInteger, ) -> Retained<Self>

§Safety

This method is unsafe because it calls an Objective-C method.

Source

pub unsafe fn setMaterial(&self, material: NSVisualEffectMaterial)

https://developer.apple.com/documentation/appkit/nsvisualeffectview/material-swift.property

§Safety

This method is unsafe because it calls an Objective-C method.

Source

pub unsafe fn setBlendingMode(&self, blending_mode: NSVisualEffectBlendingMode)

https://developer.apple.com/documentation/appkit/nsvisualeffectview/blendingmode-swift.property

§Safety

This method is unsafe because it calls an Objective-C method.

Source

pub unsafe fn setState(&self, state: NSVisualEffectState)

https://developer.apple.com/documentation/appkit/nsvisualeffectview/state-swift.property

§Safety

This method is unsafe because it calls an Objective-C method.

Source

pub unsafe fn setAutoresizingMask(&self, mask: NSAutoresizingMaskOptions)

NSView inherited method https://developer.apple.com/documentation/appkit/nsview/autoresizingmask-swift.property

§Safety

This method is unsafe because it calls an Objective-C method.

Source

pub unsafe fn setCornerRadius(&self, radius: CGFloat)

TODO: Does not seem to be public? Method is not listed in Apple documentation, might be private, but it works

§Safety

This method is unsafe because it calls an Objective-C method.

Methods from Deref<Target = NSVisualEffectView>§

Source

pub unsafe fn material(&self) -> NSVisualEffectMaterial

A value indicating which material is shown by the NSVisualEffectView. See the comments on NSVisualEffectMaterial. Defaults to NSVisualEffectMaterialAppearanceBased. You should instead specify an appropriate semantic material value. See the comments on NSVisualEffectMaterial.

Source

pub unsafe fn setMaterial(&self, material: NSVisualEffectMaterial)

Setter for material.

Source

pub unsafe fn blendingMode(&self) -> NSVisualEffectBlendingMode

A value controlling how the NSVisualEffectView generates its material. See the comments on NSVisualEffectBlendingMode. Not all materials support both blending modes, so NSVisualEffectView may fall back to a more appropriate blending mode as needed. Defaults to NSVisualEffectBlendingModeBehindWindow.

Source

pub unsafe fn setBlendingMode(&self, blending_mode: NSVisualEffectBlendingMode)

Setter for blendingMode.

Source

pub unsafe fn state(&self) -> NSVisualEffectState

A value controlling when the NSVisualEffectView takes on the active look. See the comments on NSVisualEffectState. Defaults to NSVisualEffectStateFollowsWindowActiveState.

Source

pub unsafe fn setState(&self, state: NSVisualEffectState)

Setter for state.

Source

pub unsafe fn isEmphasized(&self) -> bool

When YES, the material takes on the emphasized look. Defaults to NO. Some, but not all, materials change their look when emphasized. This is used to indicate that an associated view has firstResponder status.

Source

pub unsafe fn setEmphasized(&self, emphasized: bool)

Setter for isEmphasized.

Source

pub unsafe fn viewDidMoveToWindow(&self)

Methods from Deref<Target = NSView>§

Source

pub unsafe fn superview(&self) -> Option<Retained<NSView>>

Source

pub unsafe fn subviews(&self) -> Retained<NSArray<NSView>>

Source

pub unsafe fn setSubviews(&self, subviews: &NSArray<NSView>)

Setter for subviews.

Source

pub unsafe fn isDescendantOf(&self, view: &NSView) -> bool

Source

pub unsafe fn ancestorSharedWithView( &self, view: &NSView, ) -> Option<Retained<NSView>>

Source

pub unsafe fn opaqueAncestor(&self) -> Option<Retained<NSView>>

Source

pub unsafe fn isHidden(&self) -> bool

Source

pub fn setHidden(&self, hidden: bool)

Setter for isHidden.

Source

pub unsafe fn isHiddenOrHasHiddenAncestor(&self) -> bool

Source

pub unsafe fn getRectsBeingDrawn_count( &self, rects: *mut *const CGRect, count: *mut isize, )

Source

pub unsafe fn needsToDrawRect(&self, rect: CGRect) -> bool

Source

pub unsafe fn wantsDefaultClipping(&self) -> bool

Source

pub unsafe fn viewDidHide(&self)

Source

pub unsafe fn viewDidUnhide(&self)

Source

pub unsafe fn addSubview(&self, view: &NSView)

Source

pub unsafe fn addSubview_positioned_relativeTo( &self, view: &NSView, place: NSWindowOrderingMode, other_view: Option<&NSView>, )

Source

pub unsafe fn sortSubviewsUsingFunction_context( &self, compare: unsafe extern "C-unwind" fn(_: NonNull<NSView>, _: NonNull<NSView>, _: *mut c_void) -> NSComparisonResult, context: *mut c_void, )

Source

pub unsafe fn viewDidMoveToWindow(&self)

Source

pub unsafe fn viewWillMoveToSuperview(&self, new_superview: Option<&NSView>)

Source

pub unsafe fn viewDidMoveToSuperview(&self)

Source

pub unsafe fn didAddSubview(&self, subview: &NSView)

Source

pub unsafe fn willRemoveSubview(&self, subview: &NSView)

Source

pub unsafe fn removeFromSuperview(&self)

Source

pub unsafe fn replaceSubview_with(&self, old_view: &NSView, new_view: &NSView)

Source

pub unsafe fn removeFromSuperviewWithoutNeedingDisplay(&self)

Source

pub unsafe fn viewDidChangeBackingProperties(&self)

Source

pub unsafe fn postsFrameChangedNotifications(&self) -> bool

Source

pub fn setPostsFrameChangedNotifications( &self, posts_frame_changed_notifications: bool, )

Source

pub unsafe fn resizeSubviewsWithOldSize(&self, old_size: CGSize)

Source

pub unsafe fn resizeWithOldSuperviewSize(&self, old_size: CGSize)

Source

pub unsafe fn autoresizesSubviews(&self) -> bool

Source

pub unsafe fn setAutoresizesSubviews(&self, autoresizes_subviews: bool)

Setter for autoresizesSubviews.

Source

pub unsafe fn autoresizingMask(&self) -> NSAutoresizingMaskOptions

Source

pub unsafe fn setAutoresizingMask( &self, autoresizing_mask: NSAutoresizingMaskOptions, )

Setter for autoresizingMask.

Source

pub unsafe fn setFrameOrigin(&self, new_origin: CGPoint)

Source

pub unsafe fn setFrameSize(&self, new_size: CGSize)

Source

pub fn frame(&self) -> CGRect

Source

pub unsafe fn setFrame(&self, frame: CGRect)

Setter for frame.

Source

pub unsafe fn setBoundsOrigin(&self, new_origin: CGPoint)

Source

pub unsafe fn setBoundsSize(&self, new_size: CGSize)

Source

pub unsafe fn translateOriginToPoint(&self, translation: CGPoint)

Source

pub unsafe fn scaleUnitSquareToSize(&self, new_unit_size: CGSize)

Source

pub fn bounds(&self) -> CGRect

Source

pub unsafe fn setBounds(&self, bounds: CGRect)

Setter for bounds.

Source

pub fn isFlipped(&self) -> bool

Source

pub unsafe fn isRotatedFromBase(&self) -> bool

Source

pub unsafe fn isRotatedOrScaledFromBase(&self) -> bool

Source

pub unsafe fn isOpaque(&self) -> bool

Source

pub fn convertPoint_fromView( &self, point: CGPoint, view: Option<&NSView>, ) -> CGPoint

Source

pub unsafe fn convertPoint_toView( &self, point: CGPoint, view: Option<&NSView>, ) -> CGPoint

Source

pub unsafe fn convertSize_fromView( &self, size: CGSize, view: Option<&NSView>, ) -> CGSize

Source

pub unsafe fn convertSize_toView( &self, size: CGSize, view: Option<&NSView>, ) -> CGSize

Source

pub unsafe fn convertRect_fromView( &self, rect: CGRect, view: Option<&NSView>, ) -> CGRect

Source

pub fn convertRect_toView(&self, rect: CGRect, view: Option<&NSView>) -> CGRect

Source

pub unsafe fn backingAlignedRect_options( &self, rect: CGRect, options: NSAlignmentOptions, ) -> CGRect

Source

pub unsafe fn centerScanRect(&self, rect: CGRect) -> CGRect

Source

pub unsafe fn convertPointToBacking(&self, point: CGPoint) -> CGPoint

Source

pub unsafe fn convertPointFromBacking(&self, point: CGPoint) -> CGPoint

Source

pub unsafe fn convertSizeToBacking(&self, size: CGSize) -> CGSize

Source

pub unsafe fn convertSizeFromBacking(&self, size: CGSize) -> CGSize

Source

pub unsafe fn convertRectToBacking(&self, rect: CGRect) -> CGRect

Source

pub unsafe fn convertRectFromBacking(&self, rect: CGRect) -> CGRect

Source

pub unsafe fn convertPointToLayer(&self, point: CGPoint) -> CGPoint

Source

pub unsafe fn convertPointFromLayer(&self, point: CGPoint) -> CGPoint

Source

pub unsafe fn convertSizeToLayer(&self, size: CGSize) -> CGSize

Source

pub unsafe fn convertSizeFromLayer(&self, size: CGSize) -> CGSize

Source

pub unsafe fn convertRectToLayer(&self, rect: CGRect) -> CGRect

Source

pub unsafe fn convertRectFromLayer(&self, rect: CGRect) -> CGRect

Source

pub unsafe fn canDrawConcurrently(&self) -> bool

Source

pub unsafe fn setCanDrawConcurrently(&self, can_draw_concurrently: bool)

Setter for canDrawConcurrently.

Source

pub unsafe fn canDraw(&self) -> bool

👎Deprecated: If a view needs display, -drawRect: or -updateLayer will be called automatically when the view is able to draw. To check whether a view is in a window, call -window. To check whether a view is hidden, call -isHiddenOrHasHiddenAncestor.
Source

pub unsafe fn setNeedsDisplayInRect(&self, invalid_rect: CGRect)

Source

pub unsafe fn needsDisplay(&self) -> bool

Source

pub unsafe fn setNeedsDisplay(&self, needs_display: bool)

Setter for needsDisplay.

Source

pub unsafe fn lockFocus(&self)

👎Deprecated: To draw, subclass NSView and implement -drawRect:; AppKit’s automatic deferred display mechanism will call -drawRect: as necessary to display the view.
Source

pub unsafe fn unlockFocus(&self)

👎Deprecated: To draw, subclass NSView and implement -drawRect:; AppKit’s automatic deferred display mechanism will call -drawRect: as necessary to display the view.
Source

pub unsafe fn lockFocusIfCanDraw(&self) -> bool

👎Deprecated: To draw, subclass NSView and implement -drawRect:; AppKit’s automatic deferred display mechanism will call -drawRect: as necessary to display the view.
Source

pub fn visibleRect(&self) -> CGRect

The portion of the view that isn’t clipped by its superviews.

Visibility, as reflected by this property, doesn’t account for whether other view or window objects overlap the current view or whether the current view is installed in a window at all. This value of this property is NSZeroRect if the current view is effectively hidden.

During a printing operation, the visible rectangle is further clipped to the page being imaged.

Source

pub unsafe fn display(&self)

Source

pub unsafe fn displayIfNeeded(&self)

Source

pub unsafe fn displayIfNeededIgnoringOpacity(&self)

Source

pub unsafe fn displayRect(&self, rect: CGRect)

Source

pub unsafe fn displayIfNeededInRect(&self, rect: CGRect)

Source

pub unsafe fn displayRectIgnoringOpacity(&self, rect: CGRect)

Source

pub unsafe fn displayIfNeededInRectIgnoringOpacity(&self, rect: CGRect)

Source

pub unsafe fn drawRect(&self, dirty_rect: CGRect)

Source

pub unsafe fn viewWillDraw(&self)

Source

pub unsafe fn scrollPoint(&self, point: CGPoint)

Source

pub unsafe fn scrollRectToVisible(&self, rect: CGRect) -> bool

Source

pub unsafe fn adjustScroll(&self, new_visible: CGRect) -> CGRect

Source

pub unsafe fn scrollRect_by(&self, rect: CGRect, delta: CGSize)

👎Deprecated: Use NSScrollView to achieve scrolling views.
Source

pub unsafe fn translateRectsNeedingDisplayInRect_by( &self, clip_rect: CGRect, delta: CGSize, )

Source

pub unsafe fn hitTest(&self, point: CGPoint) -> Option<Retained<NSView>>

Source

pub unsafe fn mouse_inRect(&self, point: CGPoint, rect: CGRect) -> bool

Source

pub unsafe fn viewWithTag(&self, tag: isize) -> Option<Retained<NSView>>

Source

pub unsafe fn tag(&self) -> isize

Source

pub unsafe fn needsPanelToBecomeKey(&self) -> bool

Source

pub unsafe fn mouseDownCanMoveWindow(&self) -> bool

Source

pub unsafe fn acceptsTouchEvents(&self) -> bool

👎Deprecated: Use allowedTouchTypes instead
Source

pub unsafe fn setAcceptsTouchEvents(&self, accepts_touch_events: bool)

👎Deprecated: Use allowedTouchTypes instead

Setter for acceptsTouchEvents.

Source

pub unsafe fn wantsRestingTouches(&self) -> bool

Source

pub unsafe fn setWantsRestingTouches(&self, wants_resting_touches: bool)

Setter for wantsRestingTouches.

Source

pub unsafe fn layerContentsRedrawPolicy( &self, ) -> NSViewLayerContentsRedrawPolicy

Source

pub unsafe fn setLayerContentsRedrawPolicy( &self, layer_contents_redraw_policy: NSViewLayerContentsRedrawPolicy, )

Source

pub unsafe fn layerContentsPlacement(&self) -> NSViewLayerContentsPlacement

Source

pub unsafe fn setLayerContentsPlacement( &self, layer_contents_placement: NSViewLayerContentsPlacement, )

Source

pub unsafe fn wantsLayer(&self) -> bool

Source

pub fn setWantsLayer(&self, wants_layer: bool)

Setter for wantsLayer.

Source

pub unsafe fn wantsUpdateLayer(&self) -> bool

Source

pub unsafe fn updateLayer(&self)

Source

pub unsafe fn canDrawSubviewsIntoLayer(&self) -> bool

Source

pub unsafe fn setCanDrawSubviewsIntoLayer( &self, can_draw_subviews_into_layer: bool, )

Source

pub unsafe fn layoutSubtreeIfNeeded(&self)

Source

pub unsafe fn layout(&self)

Source

pub unsafe fn needsLayout(&self) -> bool

Source

pub unsafe fn setNeedsLayout(&self, needs_layout: bool)

Setter for needsLayout.

Source

pub unsafe fn layerUsesCoreImageFilters(&self) -> bool

Source

pub unsafe fn setLayerUsesCoreImageFilters( &self, layer_uses_core_image_filters: bool, )

Source

pub unsafe fn clipsToBounds(&self) -> bool

Source

pub unsafe fn setClipsToBounds(&self, clips_to_bounds: bool)

Setter for clipsToBounds.

Source

pub unsafe fn postsBoundsChangedNotifications(&self) -> bool

Source

pub unsafe fn setPostsBoundsChangedNotifications( &self, posts_bounds_changed_notifications: bool, )

Source

pub unsafe fn toolTip(&self) -> Option<Retained<NSString>>

Source

pub unsafe fn setToolTip(&self, tool_tip: Option<&NSString>)

Setter for toolTip.

Source

pub unsafe fn addToolTipRect_owner_userData( &self, rect: CGRect, owner: &AnyObject, data: *mut c_void, ) -> isize

Source

pub unsafe fn removeToolTip(&self, tag: isize)

Source

pub unsafe fn removeAllToolTips(&self)

Source

pub unsafe fn viewWillStartLiveResize(&self)

Source

pub unsafe fn viewDidEndLiveResize(&self)

Source

pub unsafe fn inLiveResize(&self) -> bool

Source

pub unsafe fn preservesContentDuringLiveResize(&self) -> bool

Source

pub unsafe fn rectPreservedDuringLiveResize(&self) -> CGRect

Source

pub unsafe fn rectForSmartMagnificationAtPoint_inRect( &self, location: CGPoint, visible_rect: CGRect, ) -> CGRect

Source

pub unsafe fn prepareForReuse(&self)

Source

pub unsafe fn prepareContentInRect(&self, rect: CGRect)

Source

pub unsafe fn preparedContentRect(&self) -> CGRect

Source

pub unsafe fn setPreparedContentRect(&self, prepared_content_rect: CGRect)

Setter for preparedContentRect.

Source

pub unsafe fn allowsVibrancy(&self) -> bool

Source

pub unsafe fn viewDidChangeEffectiveAppearance(&self)

Override point for reacting to the effective appearance of the receiver changing. At this point effectiveAppearance property reflects the new appearance.

Source

pub unsafe fn nextKeyView(&self) -> Option<Retained<NSView>>

Source

pub unsafe fn setNextKeyView(&self, next_key_view: Option<&NSView>)

Setter for nextKeyView.

Source

pub unsafe fn previousKeyView(&self) -> Option<Retained<NSView>>

Source

pub unsafe fn nextValidKeyView(&self) -> Option<Retained<NSView>>

Source

pub unsafe fn previousValidKeyView(&self) -> Option<Retained<NSView>>

Source

pub unsafe fn canBecomeKeyView(&self) -> bool

Source

pub unsafe fn setKeyboardFocusRingNeedsDisplayInRect(&self, rect: CGRect)

Source

pub unsafe fn focusRingType(&self) -> NSFocusRingType

Source

pub unsafe fn setFocusRingType(&self, focus_ring_type: NSFocusRingType)

Setter for focusRingType.

Source

pub unsafe fn drawFocusRingMask(&self)

Source

pub unsafe fn focusRingMaskBounds(&self) -> CGRect

Source

pub unsafe fn noteFocusRingMaskChanged(&self)

Source

pub unsafe fn dataWithEPSInsideRect(&self, rect: CGRect) -> Retained<NSData>

Source

pub unsafe fn dataWithPDFInsideRect(&self, rect: CGRect) -> Retained<NSData>

Source

pub unsafe fn print(&self, sender: Option<&AnyObject>)

Source

pub unsafe fn knowsPageRange(&self, range: *mut NSRange) -> bool

Source

pub unsafe fn rectForPage(&self, page: isize) -> CGRect

Source

pub unsafe fn locationOfPrintRect(&self, rect: CGRect) -> CGPoint

Source

pub unsafe fn drawPageBorderWithSize(&self, border_size: CGSize)

Source

pub unsafe fn pageHeader(&self) -> Retained<NSAttributedString>

Source

pub unsafe fn pageFooter(&self) -> Retained<NSAttributedString>

Source

pub unsafe fn drawSheetBorderWithSize(&self, border_size: CGSize)

👎Deprecated: This is never invoked and the NSView implementation does nothing
  • This method is obsolete. It will never be invoked from within AppKit, and NSView’s implementation of it does nothing. **
Source

pub unsafe fn printJobTitle(&self) -> Retained<NSString>

Source

pub unsafe fn beginDocument(&self)

Source

pub unsafe fn endDocument(&self)

Source

pub unsafe fn beginPageInRect_atPlacement( &self, rect: CGRect, location: CGPoint, )

Source

pub unsafe fn endPage(&self)

Source

pub unsafe fn unregisterDraggedTypes(&self)

Source

pub unsafe fn exitFullScreenModeWithOptions( &self, options: Option<&NSDictionary<NSString>>, )

Source

pub unsafe fn isInFullScreenMode(&self) -> bool

Source

pub unsafe fn showDefinitionForAttributedString_atPoint( &self, attr_string: Option<&NSAttributedString>, text_baseline_origin: CGPoint, )

Source

pub unsafe fn isDrawingFindIndicator(&self) -> bool

Source

pub unsafe fn safeAreaInsets(&self) -> NSEdgeInsets

Source

pub unsafe fn additionalSafeAreaInsets(&self) -> NSEdgeInsets

Source

pub unsafe fn setAdditionalSafeAreaInsets( &self, additional_safe_area_insets: NSEdgeInsets, )

Source

pub unsafe fn safeAreaRect(&self) -> CGRect

Source

pub unsafe fn updateTrackingAreas(&self)

Source

pub unsafe fn discardCursorRects(&self)

Source

pub unsafe fn resetCursorRects(&self)

Source

pub unsafe fn addTrackingRect_owner_userData_assumeInside( &self, rect: CGRect, owner: &AnyObject, data: *mut c_void, flag: bool, ) -> isize

Source

pub fn removeTrackingRect(&self, tag: isize)

Source

pub unsafe fn convertPointToBase(&self, point: CGPoint) -> CGPoint

👎Deprecated
Source

pub unsafe fn convertPointFromBase(&self, point: CGPoint) -> CGPoint

👎Deprecated
Source

pub unsafe fn convertSizeToBase(&self, size: CGSize) -> CGSize

👎Deprecated
Source

pub unsafe fn convertSizeFromBase(&self, size: CGSize) -> CGSize

👎Deprecated
Source

pub unsafe fn convertRectToBase(&self, rect: CGRect) -> CGRect

👎Deprecated
Source

pub unsafe fn convertRectFromBase(&self, rect: CGRect) -> CGRect

👎Deprecated
Source

pub unsafe fn performMnemonic(&self, string: &NSString) -> bool

👎Deprecated: This has always returned NO and had no effect on macOS
Source

pub unsafe fn shouldDrawColor(&self) -> bool

👎Deprecated: This method no longer does anything
Source

pub unsafe fn gState(&self) -> isize

👎Deprecated
Source

pub unsafe fn allocateGState(&self)

👎Deprecated
Source

pub unsafe fn setUpGState(&self)

👎Deprecated
Source

pub unsafe fn renewGState(&self)

👎Deprecated

Methods from Deref<Target = NSResponder>§

Source

pub unsafe fn nextResponder(&self) -> Option<Retained<NSResponder>>

Source

pub unsafe fn setNextResponder(&self, next_responder: Option<&NSResponder>)

Setter for nextResponder.

Source

pub unsafe fn tryToPerform_with( &self, action: Sel, object: Option<&AnyObject>, ) -> bool

Source

pub unsafe fn noResponderFor(&self, event_selector: Sel)

Source

pub unsafe fn acceptsFirstResponder(&self) -> bool

Source

pub unsafe fn becomeFirstResponder(&self) -> bool

Source

pub unsafe fn resignFirstResponder(&self) -> bool

Source

pub unsafe fn flushBufferedKeyEvents(&self)

Source

pub unsafe fn showContextHelp(&self, sender: Option<&AnyObject>)

Source

pub unsafe fn supplementalTargetForAction_sender( &self, action: Sel, sender: Option<&AnyObject>, ) -> Option<Retained<AnyObject>>

Source

pub unsafe fn undoManager(&self) -> Option<Retained<NSUndoManager>>

Source

pub unsafe fn presentError(&self, error: &NSError) -> bool

Source

pub unsafe fn willPresentError(&self, error: &NSError) -> Retained<NSError>

Source

pub unsafe fn performTextFinderAction(&self, sender: Option<&AnyObject>)

Source

pub unsafe fn newWindowForTab(&self, sender: Option<&AnyObject>)

Source

pub unsafe fn showWritingTools(&self, sender: Option<&AnyObject>)

Source

pub unsafe fn performMnemonic(&self, string: &NSString) -> bool

👎Deprecated: This has always returned NO and had no effect on macOS

Methods from Deref<Target = NSObject>§

Source

pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !

Handle messages the object doesn’t recognize.

See Apple’s documentation for details.

Methods from Deref<Target = AnyObject>§

Source

pub fn class(&self) -> &'static AnyClass

Dynamically find the class of this object.

§Example

Check that an instance of NSObject has the precise class NSObject.

use objc2::ClassType;
use objc2::runtime::NSObject;

let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Source

pub unsafe fn get_ivar<T>(&self, name: &str) -> &T
where T: Encode,

👎Deprecated: this is difficult to use correctly, use Ivar::load instead.

Use Ivar::load instead.

§Safety

The object must have an instance variable with the given name, and it must be of type T.

See Ivar::load_ptr for details surrounding this.

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: DowncastTarget,

Attempt to downcast the object to a class of type T.

This is the reference-variant. Use Retained::downcast if you want to convert a retained object to another type.

§Mutable classes

Some classes have immutable and mutable variants, such as NSString and NSMutableString.

When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.

So using this method to convert a NSString to a NSMutableString, while not unsound, is generally frowned upon unless you created the string yourself, or the API explicitly documents the string to be mutable.

See Apple’s documentation on mutability and on isKindOfClass: for more details.

§Generic classes

Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.

You can, however, safely downcast to generic collections where all the type-parameters are AnyObject.

§Panics

This works internally by calling isKindOfClass:. That means that the object must have the instance method of that name, and an exception will be thrown (if CoreFoundation is linked) or the process will abort if that is not the case. In the vast majority of cases, you don’t need to worry about this, since both root objects NSObject and NSProxy implement this method.

§Examples

Cast an NSString back and forth from NSObject.

use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};

let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();

Try (and fail) to cast an NSObject to an NSString.

use objc2_foundation::{NSObject, NSString};

let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());

Try to cast to an array of strings.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();

This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.

Downcast when processing each element instead.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);

for elem in arr {
    if let Some(data) = elem.downcast_ref::<NSString>() {
        // handle `data`
    }
}

Trait Implementations§

Source§

impl AsRef<AnyObject> for NSVisualEffectViewTagged

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<NSVisualEffectView> for NSVisualEffectViewTagged

Source§

fn as_ref(&self) -> &NSVisualEffectView

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<NSVisualEffectViewTagged> for NSVisualEffectViewTagged

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<AnyObject> for NSVisualEffectViewTagged

Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<NSVisualEffectView> for NSVisualEffectViewTagged

Source§

fn borrow(&self) -> &NSVisualEffectView

Immutably borrows from an owned value. Read more
Source§

impl ClassType for NSVisualEffectViewTagged

Source§

const NAME: &'static str = "NSVisualEffectViewTagged"

The name of the Objective-C class that this type represents. Read more
Source§

type Super = NSVisualEffectView

The superclass of this class. Read more
Source§

type ThreadKind = <<NSVisualEffectViewTagged as ClassType>::Super as ClassType>::ThreadKind

Whether the type can be used from any thread, or from only the main thread. Read more
Source§

fn class() -> &'static AnyClass

Get a reference to the Objective-C class that this type represents. Read more
Source§

fn as_super(&self) -> &Self::Super

Get an immutable reference to the superclass.
Source§

impl DefinedClass for NSVisualEffectViewTagged

Source§

type Ivars = NSVisualEffectViewTaggedIvars

A type representing the instance variables that this class carries.
Source§

fn ivars(&self) -> &Self::Ivars
where Self: Sized,

Get a reference to the instance variable data that this object carries.
Source§

impl Deref for NSVisualEffectViewTagged

Source§

type Target = NSVisualEffectView

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Message for NSVisualEffectViewTagged

Source§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

impl RefEncode for NSVisualEffectViewTagged

Source§

const ENCODING_REF: Encoding = <NSVisualEffectView as ::objc2::RefEncode>::ENCODING_REF

The Objective-C type-encoding for a reference of this type. Read more
Source§

impl DowncastTarget for NSVisualEffectViewTagged

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, T> MainThreadOnly for T
where T: ClassType<ThreadKind = dyn MainThreadOnly + 'a> + ?Sized,

Source§

fn mtm(&self) -> MainThreadMarker

Get a MainThreadMarker from the main-thread-only object. Read more
Source§

fn alloc(mtm: MainThreadMarker) -> Allocated<Self>
where Self: Sized + ClassType,

Allocate a new instance of the class on the main thread. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,