pub struct CNContact { /* private fields */ }CNContact only.Expand description
An immutable value object representing a contact.
CNContact is thread safe.
If using a CNContact instance where you are not certain of the keys that were fetched, use isKeyAvailable: or areKeysAvailable:. If these return NO you need to refetch the contact by the contact identifier with the keys you want to fetch. Accessing a property that was not fetched will throw CNContactPropertyNotFetchedExceptionName.
See also Apple’s documentation
Implementations§
Source§impl CNContact
impl CNContact
Sourcepub unsafe fn identifier(&self) -> Retained<NSString>
pub unsafe fn identifier(&self) -> Retained<NSString>
The identifier is unique among contacts on the device. It can be saved and used for fetching contacts next application launch.
pub unsafe fn contactType(&self) -> CNContactType
pub unsafe fn namePrefix(&self) -> Retained<NSString>
pub unsafe fn givenName(&self) -> Retained<NSString>
pub unsafe fn middleName(&self) -> Retained<NSString>
pub unsafe fn familyName(&self) -> Retained<NSString>
pub unsafe fn previousFamilyName(&self) -> Retained<NSString>
pub unsafe fn nameSuffix(&self) -> Retained<NSString>
pub unsafe fn nickname(&self) -> Retained<NSString>
pub unsafe fn organizationName(&self) -> Retained<NSString>
pub unsafe fn departmentName(&self) -> Retained<NSString>
pub unsafe fn jobTitle(&self) -> Retained<NSString>
pub unsafe fn phoneticGivenName(&self) -> Retained<NSString>
pub unsafe fn phoneticMiddleName(&self) -> Retained<NSString>
pub unsafe fn phoneticFamilyName(&self) -> Retained<NSString>
pub unsafe fn phoneticOrganizationName(&self) -> Retained<NSString>
pub unsafe fn note(&self) -> Retained<NSString>
pub unsafe fn imageData(&self) -> Option<Retained<NSData>>
pub unsafe fn thumbnailImageData(&self) -> Option<Retained<NSData>>
pub unsafe fn imageDataAvailable(&self) -> bool
pub unsafe fn phoneNumbers( &self, ) -> Retained<NSArray<CNLabeledValue<CNPhoneNumber>>>
CNLabeledValue and CNPhoneNumber only.pub unsafe fn emailAddresses( &self, ) -> Retained<NSArray<CNLabeledValue<NSString>>>
CNLabeledValue only.pub unsafe fn postalAddresses( &self, ) -> Retained<NSArray<CNLabeledValue<CNPostalAddress>>>
CNLabeledValue and CNPostalAddress only.pub unsafe fn urlAddresses(&self) -> Retained<NSArray<CNLabeledValue<NSString>>>
CNLabeledValue only.pub unsafe fn contactRelations( &self, ) -> Retained<NSArray<CNLabeledValue<CNContactRelation>>>
CNContactRelation and CNLabeledValue only.CNLabeledValue and CNSocialProfile only.pub unsafe fn instantMessageAddresses( &self, ) -> Retained<NSArray<CNLabeledValue<CNInstantMessageAddress>>>
CNInstantMessageAddress and CNLabeledValue only.Sourcepub unsafe fn birthday(&self) -> Option<Retained<NSDateComponents>>
pub unsafe fn birthday(&self) -> Option<Retained<NSDateComponents>>
The Gregorian birthday.
Sourcepub unsafe fn nonGregorianBirthday(&self) -> Option<Retained<NSDateComponents>>
pub unsafe fn nonGregorianBirthday(&self) -> Option<Retained<NSDateComponents>>
The alternate birthday (Lunisolar).
Sourcepub unsafe fn dates(
&self,
) -> Retained<NSArray<CNLabeledValue<NSDateComponents>>>
Available on crate feature CNLabeledValue only.
pub unsafe fn dates( &self, ) -> Retained<NSArray<CNLabeledValue<NSDateComponents>>>
CNLabeledValue only.Other Gregorian dates (anniversaries, etc).
Sourcepub unsafe fn isKeyAvailable(&self, key: &NSString) -> bool
pub unsafe fn isKeyAvailable(&self, key: &NSString) -> bool
Returns YES if the value for the specified key was fetched.
Sourcepub unsafe fn areKeysAvailable(
&self,
key_descriptors: &NSArray<ProtocolObject<dyn CNKeyDescriptor>>,
) -> bool
pub unsafe fn areKeysAvailable( &self, key_descriptors: &NSArray<ProtocolObject<dyn CNKeyDescriptor>>, ) -> bool
Returns YES if the values for the keys specified by all the descriptors were fetched.
Sourcepub unsafe fn localizedStringForKey(key: &NSString) -> Retained<NSString>
pub unsafe fn localizedStringForKey(key: &NSString) -> Retained<NSString>
Returns a user displayable property name.
Sourcepub unsafe fn comparatorForNameSortOrder(
sort_order: CNContactSortOrder,
) -> NSComparator
pub unsafe fn comparatorForNameSortOrder( sort_order: CNContactSortOrder, ) -> NSComparator
The contact comparator for a given sort order.
§Safety
- The returned block’s argument 1 must be a valid pointer.
- The returned block’s argument 2 must be a valid pointer.
Sourcepub unsafe fn descriptorForAllComparatorKeys() -> Retained<ProtocolObject<dyn CNKeyDescriptor>>
pub unsafe fn descriptorForAllComparatorKeys() -> Retained<ProtocolObject<dyn CNKeyDescriptor>>
Use to fetch all contact keys required for the contact sort comparator.
Sourcepub unsafe fn isUnifiedWithContactWithIdentifier(
&self,
contact_identifier: &NSString,
) -> bool
pub unsafe fn isUnifiedWithContactWithIdentifier( &self, contact_identifier: &NSString, ) -> bool
Returns YES if the receiver was fetched as a unified contact and includes the contact having contactIdentifier in its unification
impl CNContact
NSItemProvider.
Source§impl CNContact
Predicates.
impl CNContact
Predicates.
The predicates to match contacts against.
Can only use these predicates with CNContactStore and CNContactFetchRequest.
Sourcepub unsafe fn predicateForContactsMatchingName(
name: &NSString,
) -> Retained<NSPredicate>
Available on crate feature CNContact_Predicates only.
pub unsafe fn predicateForContactsMatchingName( name: &NSString, ) -> Retained<NSPredicate>
CNContact_Predicates only.To fetch contacts matching a name.
The name can contain any number of words.
Sourcepub unsafe fn predicateForContactsMatchingEmailAddress(
email_address: &NSString,
) -> Retained<NSPredicate>
Available on crate feature CNContact_Predicates only.
pub unsafe fn predicateForContactsMatchingEmailAddress( email_address: &NSString, ) -> Retained<NSPredicate>
CNContact_Predicates only.Fetch contacts matching an email address.
Use this predicate to find the contact(s) which contain the specified email address. The search is not case-sensitive.
Parameter emailAddress: The email address to search for. Do not include a scheme (e.g., “mailto:”).
Sourcepub unsafe fn predicateForContactsMatchingPhoneNumber(
phone_number: &CNPhoneNumber,
) -> Retained<NSPredicate>
Available on crate features CNContact_Predicates and CNPhoneNumber only.
pub unsafe fn predicateForContactsMatchingPhoneNumber( phone_number: &CNPhoneNumber, ) -> Retained<NSPredicate>
CNContact_Predicates and CNPhoneNumber only.Fetch contacts matching a phone number.
If the predicate and contact differ in their use or presence of country codes, a best effort will be made to match results; however, inexact matches are not guaranteed.
Parameter phoneNumber: A
CNPhoneNumberrepresenting the phone number to search for.
Do not include a scheme (e.g., “tel:”).
Sourcepub unsafe fn predicateForContactsWithIdentifiers(
identifiers: &NSArray<NSString>,
) -> Retained<NSPredicate>
Available on crate feature CNContact_Predicates only.
pub unsafe fn predicateForContactsWithIdentifiers( identifiers: &NSArray<NSString>, ) -> Retained<NSPredicate>
CNContact_Predicates only.To fetch contacts matching contact identifiers.
pub unsafe fn predicateForContactsInGroupWithIdentifier( group_identifier: &NSString, ) -> Retained<NSPredicate>
CNContact_Predicates only.pub unsafe fn predicateForContactsInContainerWithIdentifier( container_identifier: &NSString, ) -> Retained<NSPredicate>
CNContact_Predicates only.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<CNContact> for CNMutableContact
Available on crate feature CNMutableContact only.
impl AsRef<CNContact> for CNMutableContact
CNMutableContact only.Source§impl Borrow<CNContact> for CNMutableContact
Available on crate feature CNMutableContact only.
impl Borrow<CNContact> for CNMutableContact
CNMutableContact only.Source§impl ClassType for CNContact
impl ClassType for CNContact
Source§const NAME: &'static str = "CNContact"
const NAME: &'static str = "CNContact"
Source§type ThreadKind = <<CNContact as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<CNContact as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for CNContact
impl CopyingHelper for CNContact
Source§impl MutableCopyingHelper for CNContact
Available on crate feature CNMutableContact only.
impl MutableCopyingHelper for CNContact
CNMutableContact only.Source§type Result = CNMutableContact
type Result = CNMutableContact
Self if the type has no
mutable counterpart. Read moreSource§impl NSCopying for CNContact
impl NSCopying for CNContact
Source§impl NSItemProviderReading for CNContact
Available on crate feature CNContact_NSItemProvider only.
impl NSItemProviderReading for CNContact
CNContact_NSItemProvider only.Source§impl NSItemProviderWriting for CNContact
Available on crate feature CNContact_NSItemProvider only.
impl NSItemProviderWriting for CNContact
CNContact_NSItemProvider only.fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
fn writableTypeIdentifiersForItemProvider(&self) -> Retained<NSArray<NSString>>
fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class( type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
fn itemProviderVisibilityForRepresentationWithTypeIdentifier( &self, type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
Source§impl NSMutableCopying for CNContact
impl NSMutableCopying for CNContact
Source§impl NSObjectProtocol for CNContact
impl NSObjectProtocol for CNContact
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