rust_macios/contacts/
cn_container.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    foundation::{NSArray, NSPredicate, NSString},
5    object,
6    objective_c_runtime::{
7        macros::interface_impl,
8        traits::{FromId, PNSObject},
9    },
10};
11
12/// The container may be local on the device or associated with a server account that has contacts.
13#[derive(Debug, Copy, Clone, PartialEq, Eq)]
14#[repr(i64)]
15pub enum CNContainerType {
16    ///
17    Unassigned = 0,
18    /// A container for contacts only stored locally on the device. There is only one local container for a device.
19    Local,
20    /// A container for contacts stored in an Exchange folder from an Exchange server.
21    Exchange,
22    /// A container for contacts stored in an CardDAV server, such as iCloud.
23    CardDav,
24}
25
26object! {
27    /// An immutable object that represents a collection of contacts.
28    unsafe pub struct CNContainer;
29}
30
31#[interface_impl(NSObject)]
32impl CNContainer {
33    /* Getting the Container Information
34     */
35
36    /// The name of the container.
37    #[property]
38    pub fn name(&self) -> NSString {
39        unsafe { NSString::from_id(msg_send![self.m_self(), name]) }
40    }
41
42    /// The unique identifier for a contacts container on the device.
43    #[property]
44    pub fn identifier(&self) -> NSString {
45        unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
46    }
47
48    /// The type of the container.
49    #[property]
50    pub fn type_(&self) -> CNContainerType {
51        unsafe { msg_send![self.m_self(), type] }
52    }
53
54    /// Returns a predicate to find the container of the specified contact.
55    #[method]
56    pub fn predicate_for_container_of_contact_identifier(identifier: NSString) -> NSPredicate {
57        unsafe {
58            NSPredicate::from_id(msg_send![
59                Self::m_class(),
60                predicateForContainerOfContactWithIdentifier: identifier
61            ])
62        }
63    }
64
65    /// Returns a predicate to find the containers with the specified identifiers.
66    #[method]
67    pub fn predicate_for_containers_with_identifiers(
68        identifiers: NSArray<NSString>,
69    ) -> NSPredicate {
70        unsafe {
71            NSPredicate::from_id(msg_send![
72                Self::m_class(),
73                predicateForContainersWithIdentifiers: identifiers
74            ])
75        }
76    }
77
78    /// Returns a predicate to find the container of the specified group.
79    #[method]
80    pub fn predicate_for_container_of_group_with_identifier(identifier: NSString) -> NSPredicate {
81        unsafe {
82            NSPredicate::from_id(msg_send![
83                Self::m_class(),
84                predicateForContainerOfGroupWithIdentifier: identifier
85            ])
86        }
87    }
88}