Struct objc2_foundation::NSValue
source · #[repr(C)]pub struct NSValue { /* private fields */ }NSValue only.Implementations§
source§impl NSValue
impl NSValue
NSValueGeometryExtensions
pub unsafe fn valueWithPoint(point: NSPoint) -> Retained<NSValue>
NSGeometry only.pub unsafe fn valueWithSize(size: NSSize) -> Retained<NSValue>
NSGeometry only.pub unsafe fn valueWithRect(rect: NSRect) -> Retained<NSValue>
NSGeometry only.pub unsafe fn valueWithEdgeInsets(insets: NSEdgeInsets) -> Retained<NSValue>
NSGeometry only.pub unsafe fn pointValue(&self) -> NSPoint
NSGeometry only.pub unsafe fn sizeValue(&self) -> NSSize
NSGeometry only.pub unsafe fn rectValue(&self) -> NSRect
NSGeometry only.pub unsafe fn edgeInsetsValue(&self) -> NSEdgeInsets
NSGeometry only.source§impl NSValue
impl NSValue
NSValueRangeExtensions
pub unsafe fn valueWithRange(range: NSRange) -> Retained<NSValue>
NSRange only.pub unsafe fn rangeValue(&self) -> NSRange
NSRange only.source§impl NSValue
impl NSValue
pub unsafe fn getValue_size(&self, value: NonNull<c_void>, size: NSUInteger)
pub fn objCType(&self) -> NonNull<c_char>
pub unsafe fn initWithBytes_objCType( this: Allocated<Self>, value: NonNull<c_void>, type: NonNull<c_char> ) -> Retained<Self>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder ) -> Option<Retained<Self>>
NSCoder only.source§impl NSValue
impl NSValue
NSValueExtensionMethods
pub unsafe fn valueWithNonretainedObject( an_object: Option<&AnyObject> ) -> Retained<NSValue>
pub unsafe fn nonretainedObjectValue(&self) -> Option<Retained<AnyObject>>
pub unsafe fn valueWithPointer(pointer: *mut c_void) -> Retained<NSValue>
pub unsafe fn pointerValue(&self) -> *mut c_void
pub fn isEqualToValue(&self, value: &NSValue) -> bool
source§impl NSValue
impl NSValue
Creation methods.
sourcepub fn new<T: 'static + Copy + Encode>(value: T) -> Retained<Self>
pub fn new<T: 'static + Copy + Encode>(value: T) -> Retained<Self>
Create a new NSValue containing the given type.
Be careful when using this since you may accidentally pass a reference when you wanted to pass a concrete type instead.
§Examples
Create an NSValue containing an i32.
use objc2_foundation::NSValue;
let val = NSValue::new(42i32);source§impl NSValue
impl NSValue
Getter methods.
sourcepub unsafe fn get<T: 'static + Copy + Encode>(&self) -> T
pub unsafe fn get<T: 'static + Copy + Encode>(&self) -> T
Retrieve the data contained in the NSValue.
Note that this is broken on GNUStep for some types, see gnustep/libs-base#216.
§Safety
The type of T must be what the NSValue actually stores, and any
safety invariants that the value has must be upheld.
Note that it may be enough, although is not always, to check whether
contains_encoding returns true. For example, NonNull<T> have
the same encoding as *const T, but NonNull<T> is clearly not
safe to return from this function even if you’ve checked the encoding
beforehand.
§Examples
Store a pointer in NSValue, and retrieve it again afterwards.
use std::ffi::c_void;
use std::ptr;
use objc2_foundation::NSValue;
let val = NSValue::new::<*const c_void>(ptr::null());
// SAFETY: The value was just created with a pointer
let res = unsafe { val.get::<*const c_void>() };
assert!(res.is_null());pub fn get_range(&self) -> Option<NSRange>
NSRange only.pub fn get_point(&self) -> Option<NSPoint>
NSGeometry only.pub fn get_size(&self) -> Option<NSSize>
NSGeometry only.pub fn get_rect(&self) -> Option<NSRect>
NSGeometry only.pub fn encoding(&self) -> Option<&str>
pub fn contains_encoding<T: 'static + Copy + Encode>(&self) -> bool
Methods from Deref<Target = NSObject>§
sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
sourcepub fn class(&self) -> &'static AnyClass
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());sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
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.
sourcepub unsafe fn get_mut_ivar<T>(&mut self, name: &str) -> &mut Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load_mut instead.
pub unsafe fn get_mut_ivar<T>(&mut self, name: &str) -> &mut Twhere
T: Encode,
Ivar::load_mut instead.Use Ivar::load_mut 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.
Trait Implementations§
source§impl AsMut<NSValue> for NSDecimalNumber
Available on crate feature NSDecimalNumber only.
impl AsMut<NSValue> for NSDecimalNumber
NSDecimalNumber only.source§impl AsRef<NSValue> for NSDecimalNumber
Available on crate feature NSDecimalNumber only.
impl AsRef<NSValue> for NSDecimalNumber
NSDecimalNumber only.source§impl Borrow<NSValue> for NSDecimalNumber
Available on crate feature NSDecimalNumber only.
impl Borrow<NSValue> for NSDecimalNumber
NSDecimalNumber only.source§impl BorrowMut<AnyObject> for NSValue
impl BorrowMut<AnyObject> for NSValue
source§fn borrow_mut(&mut self) -> &mut AnyObject
fn borrow_mut(&mut self) -> &mut AnyObject
source§impl BorrowMut<NSObject> for NSValue
impl BorrowMut<NSObject> for NSValue
source§fn borrow_mut(&mut self) -> &mut NSObject
fn borrow_mut(&mut self) -> &mut NSObject
source§impl BorrowMut<NSValue> for NSDecimalNumber
Available on crate feature NSDecimalNumber only.
impl BorrowMut<NSValue> for NSDecimalNumber
NSDecimalNumber only.source§fn borrow_mut(&mut self) -> &mut NSValue
fn borrow_mut(&mut self) -> &mut NSValue
source§impl BorrowMut<NSValue> for NSNumber
impl BorrowMut<NSValue> for NSNumber
source§fn borrow_mut(&mut self) -> &mut NSValue
fn borrow_mut(&mut self) -> &mut NSValue
source§impl ClassType for NSValue
impl ClassType for NSValue
§type Mutability = Immutable
type Mutability = Immutable
source§const NAME: &'static str = "NSValue"
const NAME: &'static str = "NSValue"
source§fn class() -> &'static AnyClass
fn class() -> &'static AnyClass
source§fn as_super_mut(&mut self) -> &mut Self::Super
fn as_super_mut(&mut self) -> &mut Self::Super
source§impl NSCopying for NSValue
Available on crate feature NSObject only.
impl NSCopying for NSValue
NSObject only.source§impl NSObjectProtocol for NSValue
impl NSObjectProtocol for NSValue
source§fn isEqual(&self, other: &AnyObject) -> bool
fn isEqual(&self, other: &AnyObject) -> bool
source§fn hash(&self) -> usize
fn hash(&self) -> usize
source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
source§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
source§impl NSSecureCoding for NSValue
Available on crate feature NSObject only.
impl NSSecureCoding for NSValue
NSObject only.source§impl PartialEq for NSValue
impl PartialEq for NSValue
source§impl RefEncode for NSValue
impl RefEncode for NSValue
source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
source§impl ToOwned for NSValue
Available on crate feature NSObject only.
impl ToOwned for NSValue
NSObject only.impl Message for NSValue
Auto Trait Implementations§
impl !Freeze for NSValue
impl !RefUnwindSafe for NSValue
impl !Send for NSValue
impl !Sync for NSValue
impl !Unpin for NSValue
impl !UnwindSafe for NSValue
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CounterpartOrSelf for T
impl<T> CounterpartOrSelf for T
§type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable
type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable
Self if the type has no
immutable counterpart. Read more§type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable
type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable
Self if the type has no
mutable counterpart. Read more