rust_macios/contacts/
cn_contact_fetch_request.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    foundation::{NSArray, NSPredicate},
5    object,
6    objective_c_runtime::{id, macros::interface_impl, traits::FromId},
7    utils::to_bool,
8};
9
10use super::{CNContactSortOrder, ICNFetchRequest};
11
12object! {
13    /// An object that defines the options to use when fetching contacts.
14    unsafe pub struct CNContactFetchRequest;
15}
16
17impl ICNFetchRequest for CNContactFetchRequest {}
18
19#[interface_impl(CNFetchRequest)]
20impl CNContactFetchRequest {
21    /* Creating a Fetch Request
22     */
23
24    /// Creates a fetch request for the specified keys.
25    #[method]
26    pub fn init_with_keys_to_fetch(&self, keys: NSArray<id>) -> Self
27    where
28        Self: Sized + FromId,
29    {
30        unsafe { Self::from_id(msg_send![self.m_self(), initWithKeysToFetch: keys]) }
31    }
32
33    /* Specifying the Search Predicate
34     */
35
36    /// The predicate to match contacts against.
37    #[property]
38    pub fn predicate(&self) -> NSPredicate {
39        unsafe { NSPredicate::from_id(msg_send![self.m_self(), predicate]) }
40    }
41
42    /// Sets the predicate to match contacts against.
43    #[property]
44    pub fn set_predicate(&mut self, predicate: NSPredicate) {
45        unsafe { msg_send![self.m_self(), setPredicate: predicate] }
46    }
47
48    /// Configuring the Fetch Options
49    #[property]
50    pub fn mutable_objects(&self) -> bool {
51        unsafe { to_bool(msg_send![self.m_self(), mutableObjects]) }
52    }
53
54    /// Sets whether the fetch request should return mutable objects.
55    #[property]
56    pub fn set_mutable_objects(&mut self, mutable_objects: bool) {
57        unsafe { msg_send![self.m_self(), setMutableObjects: mutable_objects] }
58    }
59
60    /// A Boolean value that indicates whether to return linked contacts as unified contacts.
61    #[property]
62    pub fn unify_results(&self) -> bool {
63        unsafe { to_bool(msg_send![self.m_self(), unifyResults]) }
64    }
65
66    /// Sets whether to return linked contacts as unified contacts.
67    #[property]
68    pub fn set_unify_results(&mut self, unify_results: bool) {
69        unsafe { msg_send![self.m_self(), setUnifyResults: unify_results] }
70    }
71
72    /// The sort order for contacts.
73    #[property]
74    pub fn sort_order(&self) -> CNContactSortOrder {
75        unsafe { msg_send![self.m_self(), sortOrder] }
76    }
77
78    /* Specifying the Keys to Fetch
79     */
80
81    /// The properties to fetch in the returned contacts.
82    #[property]
83    pub fn keys_to_fetch(&self) -> NSArray<id> {
84        unsafe { NSArray::from_id(msg_send![self.m_self(), keysToFetch]) }
85    }
86
87    /// Sets the properties to fetch in the returned contacts.
88    #[property]
89    pub fn set_keys_to_fetch(&mut self, keys_to_fetch: NSArray<id>) {
90        unsafe { msg_send![self.m_self(), setKeysToFetch: keys_to_fetch] }
91    }
92}