rust_macios/contacts/
cn_instant_message_address.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 an instant message address for the contact.
14    unsafe pub struct CNInstantMessageAddress;
15}
16
17#[interface_impl(NSObject)]
18impl CNInstantMessageAddress {
19    /// Returns a CNInstantMessageAddress object initialized with the specified user name and service.
20    #[method]
21    pub fn init_with_username_service(&mut self, username: NSString, service: NSString) -> Self
22    where
23        Self: Sized + FromId,
24    {
25        unsafe {
26            Self::from_id(msg_send![self.m_self(), initWithUsername: username service: service])
27        }
28    }
29
30    /* Getting the Address Information
31     */
32
33    /// The service type of the instant message address.
34    #[property]
35    pub fn service(&self) -> NSString {
36        unsafe { NSString::from_id(msg_send![self.m_self(), service]) }
37    }
38    /// The username of the instant message address.
39    #[property]
40    pub fn username(&self) -> NSString {
41        unsafe { NSString::from_id(msg_send![self.m_self(), username]) }
42    }
43
44    /* Getting Localized Address Information
45     */
46
47    /// Returns a string containing the localized property name.
48    #[method]
49    pub fn localized_string_for_key(key: NSString) -> NSString {
50        unsafe { NSString::from_id(msg_send![Self::m_class(), localizedStringForKey: key]) }
51    }
52
53    /// Returns a string containing the localized name of the specified service.
54    #[method]
55    pub fn localized_string_for_service(service: NSString) -> NSString {
56        unsafe {
57            NSString::from_id(msg_send![
58                Self::m_class(),
59                localizedStringForService: service
60            ])
61        }
62    }
63}