rust_macios/contacts/
cn_phone_number.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 representing a phone number for a contact.
14    unsafe pub struct CNPhoneNumber;
15}
16
17#[interface_impl(NSObject)]
18impl CNPhoneNumber {
19    /* Creating a Phone Number Object
20     */
21
22    /// Returns a new phone number object initialized with the specified phone number string.
23    #[method]
24    pub fn init_with_string_value(&mut self, phone_number: NSString) -> Self
25    where
26        Self: Sized + FromId,
27    {
28        unsafe { Self::from_id(msg_send![self.m_self(), initWithString: phone_number]) }
29    }
30
31    /// Returns a new phone number object initialized with the specified phone number string.
32    #[method]
33    pub fn phone_number_with_string_value(phone_number: NSString) -> Self
34    where
35        Self: Sized + FromId,
36    {
37        unsafe {
38            Self::from_id(msg_send![
39                Self::m_class(),
40                phoneNumberWithString: phone_number
41            ])
42        }
43    }
44
45    /* Getting the Phone Number
46     */
47
48    /// The string value of the phone number.
49    #[property]
50    pub fn string_value(&self) -> NSString {
51        unsafe { NSString::from_id(msg_send![self.m_self(), stringValue]) }
52    }
53}