rust_macios/contacts/
cn_group.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
12object! {
13    /// An immutable object that represents a group of contacts.
14    unsafe pub struct CNGroup;
15}
16
17#[interface_impl(NSObject)]
18impl CNGroup {
19    /// The name of the group.
20    #[property]
21    pub fn name(&self) -> NSString {
22        unsafe { NSString::from_id(msg_send![self.m_self(), name]) }
23    }
24
25    /// The unique identifier for a group on the device.
26    #[property]
27    pub fn identifier(&self) -> NSString {
28        unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
29    }
30
31    /* Generating Search Predicates for Groups
32     */
33
34    /// Returns a predicate to find groups with the specified identifiers.
35    #[method]
36    pub fn predicate_for_groups_with_identifiers(identifiers: NSArray<NSString>) -> NSPredicate {
37        unsafe {
38            NSPredicate::from_id(msg_send![
39                CNGroup::m_class(),
40                predicateForGroupsWithIdentifiers: identifiers
41            ])
42        }
43    }
44
45    /// Returns a predicate to find groups in the specified container.
46    #[method]
47    pub fn predicate_for_groups_in_container_with_identifiers(container: NSString) -> NSPredicate {
48        unsafe {
49            NSPredicate::from_id(msg_send![
50                CNGroup::m_class(),
51                predicateForGroupsInContainer: container
52            ])
53        }
54    }
55
56    /// Returns a predicate to find subgroups in the specified parent group.
57    #[method]
58    pub fn predicate_for_subgroups_in_group_with_identifier(parent_group: NSString) -> NSPredicate {
59        unsafe {
60            NSPredicate::from_id(msg_send![
61                CNGroup::m_class(),
62                predicateForSubgroupsInGroup: parent_group
63            ])
64        }
65    }
66}