rust_macios/contacts/
cn_contact_relation.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    foundation::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 the relationship between one contact to another.
14    unsafe pub struct CNContactRelation;
15}
16
17#[interface_impl(NSObject)]
18impl CNContactRelation {
19    /// Creates an object with the name of the related contact.
20    #[method]
21    pub fn init_with_name(&mut self, name: NSString) -> Self
22    where
23        Self: Sized + FromId,
24    {
25        unsafe { Self::from_id(msg_send![self.m_self(), initWithName: name]) }
26    }
27
28    /// Instantiate a class instance with the name of the related contact.
29    #[method]
30    pub fn m_contact_relation_with_name(name: NSString) -> Self
31    where
32        Self: Sized + FromId,
33    {
34        unsafe { Self::from_id(msg_send![Self::m_class(), contactRelationWithName: name]) }
35    }
36
37    /// The name of the related contact.
38    #[property]
39    pub fn name(&self) -> NSString {
40        unsafe { NSString::from_id(msg_send![self.m_self(), name]) }
41    }
42}