pub struct HKObject { /* private fields */ }HKObject only.Expand description
Implementations§
Source§impl HKObject
impl HKObject
Sourcepub unsafe fn UUID(&self) -> Retained<NSUUID>
pub unsafe fn UUID(&self) -> Retained<NSUUID>
A unique identifier of the receiver in the HealthKit database.
pub unsafe fn source(&self) -> Retained<HKSource>
HKSource only.Sourcepub unsafe fn sourceRevision(&self) -> Retained<HKSourceRevision>
Available on crate feature HKSourceRevision only.
pub unsafe fn sourceRevision(&self) -> Retained<HKSourceRevision>
HKSourceRevision only.Represents the revision of the source responsible for saving the receiver.
Sourcepub unsafe fn device(&self) -> Option<Retained<HKDevice>>
Available on crate feature HKDevice only.
pub unsafe fn device(&self) -> Option<Retained<HKDevice>>
HKDevice only.Represents the device that generated the data of the receiver.
Sourcepub unsafe fn metadata(
&self,
) -> Option<Retained<NSDictionary<NSString, AnyObject>>>
pub unsafe fn metadata( &self, ) -> Option<Retained<NSDictionary<NSString, AnyObject>>>
Extra information describing properties of the receiver.
Keys must be NSString and values must be either NSString, NSNumber, NSDate, or HKQuantity. See HKMetadata.h for potential metadata keys and values.
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
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.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§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 fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
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<HKObject> for HKAudiogramSample
Available on crate features HKSample and HKAudiogramSample only.
impl AsRef<HKObject> for HKAudiogramSample
HKSample and HKAudiogramSample only.Source§impl AsRef<HKObject> for HKCDADocumentSample
Available on crate features HKDocumentSample and HKSample and HKCDADocumentSample only.
impl AsRef<HKObject> for HKCDADocumentSample
HKDocumentSample and HKSample and HKCDADocumentSample only.Source§impl AsRef<HKObject> for HKCategorySample
Available on crate features HKSample and HKCategorySample only.
impl AsRef<HKObject> for HKCategorySample
HKSample and HKCategorySample only.Source§impl AsRef<HKObject> for HKClinicalRecord
Available on crate features HKSample and HKClinicalRecord only.
impl AsRef<HKObject> for HKClinicalRecord
HKSample and HKClinicalRecord only.Source§impl AsRef<HKObject> for HKContactsPrescription
Available on crate features HKSample and HKVisionPrescription and HKContactsPrescription only.
impl AsRef<HKObject> for HKContactsPrescription
HKSample and HKVisionPrescription and HKContactsPrescription only.Source§impl AsRef<HKObject> for HKCorrelation
Available on crate features HKSample and HKCorrelation only.
impl AsRef<HKObject> for HKCorrelation
HKSample and HKCorrelation only.Source§impl AsRef<HKObject> for HKCumulativeQuantitySample
Available on crate features HKQuantitySample and HKSample and HKCumulativeQuantitySample only.
impl AsRef<HKObject> for HKCumulativeQuantitySample
HKQuantitySample and HKSample and HKCumulativeQuantitySample only.Source§impl AsRef<HKObject> for HKCumulativeQuantitySeriesSample
Available on crate features HKCumulativeQuantitySample and HKQuantitySample and HKSample and HKCumulativeQuantitySeriesSample only.
impl AsRef<HKObject> for HKCumulativeQuantitySeriesSample
HKCumulativeQuantitySample and HKQuantitySample and HKSample and HKCumulativeQuantitySeriesSample only.Source§impl AsRef<HKObject> for HKDiscreteQuantitySample
Available on crate features HKQuantitySample and HKSample and HKDiscreteQuantitySample only.
impl AsRef<HKObject> for HKDiscreteQuantitySample
HKQuantitySample and HKSample and HKDiscreteQuantitySample only.Source§impl AsRef<HKObject> for HKDocumentSample
Available on crate features HKSample and HKDocumentSample only.
impl AsRef<HKObject> for HKDocumentSample
HKSample and HKDocumentSample only.Source§impl AsRef<HKObject> for HKElectrocardiogram
Available on crate features HKSample and HKElectrocardiogram only.
impl AsRef<HKObject> for HKElectrocardiogram
HKSample and HKElectrocardiogram only.Source§impl AsRef<HKObject> for HKGAD7Assessment
Available on crate features HKSample and HKScoredAssessment and HKGAD7Assessment only.
impl AsRef<HKObject> for HKGAD7Assessment
HKSample and HKScoredAssessment and HKGAD7Assessment only.Source§impl AsRef<HKObject> for HKGlassesPrescription
Available on crate features HKSample and HKVisionPrescription and HKGlassesPrescription only.
impl AsRef<HKObject> for HKGlassesPrescription
HKSample and HKVisionPrescription and HKGlassesPrescription only.Source§impl AsRef<HKObject> for HKHeartbeatSeriesSample
Available on crate features HKSample and HKSeriesSample and HKHeartbeatSeriesSample only.
impl AsRef<HKObject> for HKHeartbeatSeriesSample
HKSample and HKSeriesSample and HKHeartbeatSeriesSample only.Source§impl AsRef<HKObject> for HKMedicationDoseEvent
Available on crate features HKSample and HKMedicationDoseEvent only.
impl AsRef<HKObject> for HKMedicationDoseEvent
HKSample and HKMedicationDoseEvent only.Source§impl AsRef<HKObject> for HKPHQ9Assessment
Available on crate features HKSample and HKScoredAssessment and HKPHQ9Assessment only.
impl AsRef<HKObject> for HKPHQ9Assessment
HKSample and HKScoredAssessment and HKPHQ9Assessment only.Source§impl AsRef<HKObject> for HKQuantitySample
Available on crate features HKSample and HKQuantitySample only.
impl AsRef<HKObject> for HKQuantitySample
HKSample and HKQuantitySample only.Source§impl AsRef<HKObject> for HKScoredAssessment
Available on crate features HKSample and HKScoredAssessment only.
impl AsRef<HKObject> for HKScoredAssessment
HKSample and HKScoredAssessment only.Source§impl AsRef<HKObject> for HKSeriesSample
Available on crate features HKSample and HKSeriesSample only.
impl AsRef<HKObject> for HKSeriesSample
HKSample and HKSeriesSample only.Source§impl AsRef<HKObject> for HKStateOfMind
Available on crate features HKSample and HKStateOfMind only.
impl AsRef<HKObject> for HKStateOfMind
HKSample and HKStateOfMind only.Source§impl AsRef<HKObject> for HKVerifiableClinicalRecord
Available on crate features HKSample and HKVerifiableClinicalRecord only.
impl AsRef<HKObject> for HKVerifiableClinicalRecord
HKSample and HKVerifiableClinicalRecord only.Source§impl AsRef<HKObject> for HKVisionPrescription
Available on crate features HKSample and HKVisionPrescription only.
impl AsRef<HKObject> for HKVisionPrescription
HKSample and HKVisionPrescription only.Source§impl AsRef<HKObject> for HKWorkoutRoute
Available on crate features HKSample and HKSeriesSample and HKWorkoutRoute only.
impl AsRef<HKObject> for HKWorkoutRoute
HKSample and HKSeriesSample and HKWorkoutRoute only.Source§impl Borrow<HKObject> for HKAudiogramSample
Available on crate features HKSample and HKAudiogramSample only.
impl Borrow<HKObject> for HKAudiogramSample
HKSample and HKAudiogramSample only.Source§impl Borrow<HKObject> for HKCDADocumentSample
Available on crate features HKDocumentSample and HKSample and HKCDADocumentSample only.
impl Borrow<HKObject> for HKCDADocumentSample
HKDocumentSample and HKSample and HKCDADocumentSample only.Source§impl Borrow<HKObject> for HKCategorySample
Available on crate features HKSample and HKCategorySample only.
impl Borrow<HKObject> for HKCategorySample
HKSample and HKCategorySample only.Source§impl Borrow<HKObject> for HKClinicalRecord
Available on crate features HKSample and HKClinicalRecord only.
impl Borrow<HKObject> for HKClinicalRecord
HKSample and HKClinicalRecord only.Source§impl Borrow<HKObject> for HKContactsPrescription
Available on crate features HKSample and HKVisionPrescription and HKContactsPrescription only.
impl Borrow<HKObject> for HKContactsPrescription
HKSample and HKVisionPrescription and HKContactsPrescription only.Source§impl Borrow<HKObject> for HKCorrelation
Available on crate features HKSample and HKCorrelation only.
impl Borrow<HKObject> for HKCorrelation
HKSample and HKCorrelation only.Source§impl Borrow<HKObject> for HKCumulativeQuantitySample
Available on crate features HKQuantitySample and HKSample and HKCumulativeQuantitySample only.
impl Borrow<HKObject> for HKCumulativeQuantitySample
HKQuantitySample and HKSample and HKCumulativeQuantitySample only.Source§impl Borrow<HKObject> for HKCumulativeQuantitySeriesSample
Available on crate features HKCumulativeQuantitySample and HKQuantitySample and HKSample and HKCumulativeQuantitySeriesSample only.
impl Borrow<HKObject> for HKCumulativeQuantitySeriesSample
HKCumulativeQuantitySample and HKQuantitySample and HKSample and HKCumulativeQuantitySeriesSample only.Source§impl Borrow<HKObject> for HKDiscreteQuantitySample
Available on crate features HKQuantitySample and HKSample and HKDiscreteQuantitySample only.
impl Borrow<HKObject> for HKDiscreteQuantitySample
HKQuantitySample and HKSample and HKDiscreteQuantitySample only.Source§impl Borrow<HKObject> for HKDocumentSample
Available on crate features HKSample and HKDocumentSample only.
impl Borrow<HKObject> for HKDocumentSample
HKSample and HKDocumentSample only.Source§impl Borrow<HKObject> for HKElectrocardiogram
Available on crate features HKSample and HKElectrocardiogram only.
impl Borrow<HKObject> for HKElectrocardiogram
HKSample and HKElectrocardiogram only.Source§impl Borrow<HKObject> for HKGAD7Assessment
Available on crate features HKSample and HKScoredAssessment and HKGAD7Assessment only.
impl Borrow<HKObject> for HKGAD7Assessment
HKSample and HKScoredAssessment and HKGAD7Assessment only.Source§impl Borrow<HKObject> for HKGlassesPrescription
Available on crate features HKSample and HKVisionPrescription and HKGlassesPrescription only.
impl Borrow<HKObject> for HKGlassesPrescription
HKSample and HKVisionPrescription and HKGlassesPrescription only.Source§impl Borrow<HKObject> for HKHeartbeatSeriesSample
Available on crate features HKSample and HKSeriesSample and HKHeartbeatSeriesSample only.
impl Borrow<HKObject> for HKHeartbeatSeriesSample
HKSample and HKSeriesSample and HKHeartbeatSeriesSample only.Source§impl Borrow<HKObject> for HKMedicationDoseEvent
Available on crate features HKSample and HKMedicationDoseEvent only.
impl Borrow<HKObject> for HKMedicationDoseEvent
HKSample and HKMedicationDoseEvent only.Source§impl Borrow<HKObject> for HKPHQ9Assessment
Available on crate features HKSample and HKScoredAssessment and HKPHQ9Assessment only.
impl Borrow<HKObject> for HKPHQ9Assessment
HKSample and HKScoredAssessment and HKPHQ9Assessment only.Source§impl Borrow<HKObject> for HKQuantitySample
Available on crate features HKSample and HKQuantitySample only.
impl Borrow<HKObject> for HKQuantitySample
HKSample and HKQuantitySample only.Source§impl Borrow<HKObject> for HKScoredAssessment
Available on crate features HKSample and HKScoredAssessment only.
impl Borrow<HKObject> for HKScoredAssessment
HKSample and HKScoredAssessment only.Source§impl Borrow<HKObject> for HKSeriesSample
Available on crate features HKSample and HKSeriesSample only.
impl Borrow<HKObject> for HKSeriesSample
HKSample and HKSeriesSample only.Source§impl Borrow<HKObject> for HKStateOfMind
Available on crate features HKSample and HKStateOfMind only.
impl Borrow<HKObject> for HKStateOfMind
HKSample and HKStateOfMind only.Source§impl Borrow<HKObject> for HKVerifiableClinicalRecord
Available on crate features HKSample and HKVerifiableClinicalRecord only.
impl Borrow<HKObject> for HKVerifiableClinicalRecord
HKSample and HKVerifiableClinicalRecord only.Source§impl Borrow<HKObject> for HKVisionPrescription
Available on crate features HKSample and HKVisionPrescription only.
impl Borrow<HKObject> for HKVisionPrescription
HKSample and HKVisionPrescription only.Source§impl Borrow<HKObject> for HKWorkoutRoute
Available on crate features HKSample and HKSeriesSample and HKWorkoutRoute only.
impl Borrow<HKObject> for HKWorkoutRoute
HKSample and HKSeriesSample and HKWorkoutRoute only.Source§impl ClassType for HKObject
impl ClassType for HKObject
Source§const NAME: &'static str = "HKObject"
const NAME: &'static str = "HKObject"
Source§type ThreadKind = <<HKObject as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<HKObject as ClassType>::Super as ClassType>::ThreadKind
Source§impl NSObjectProtocol for HKObject
impl NSObjectProtocol for HKObject
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&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
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref