rust_macios/contacts/
cn_social_profile.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 one of the user's social profiles.
14    unsafe pub struct CNSocialProfile;
15}
16
17#[interface_impl(NSObject)]
18impl CNSocialProfile {
19    /// Initializes a new social profile object with the specified URL.
20    #[method]
21    pub fn init_with_url_string_username_user_identifier_service(
22        &mut self,
23        url_string: NSString,
24        username: NSString,
25        user_identifier: NSString,
26        service: NSString,
27    ) -> Self
28    where
29        Self: Sized + FromId,
30    {
31        unsafe {
32            Self::from_id(
33                msg_send![self.m_self(), initWithUrlString: url_string username: username userIdentifier: user_identifier service: service],
34            )
35        }
36    }
37
38    /* Getting Social Profile Information
39     */
40
41    /// The user name for the social profile.
42    #[property]
43    pub fn username(&self) -> NSString {
44        unsafe { NSString::from_id(msg_send![self.m_self(), username]) }
45    }
46
47    /// The social profile’s service name.
48    #[property]
49    pub fn service(&self) -> NSString {
50        unsafe { NSString::from_id(msg_send![self.m_self(), service]) }
51    }
52
53    /// The URL associated with the social profile.
54    #[property]
55    pub fn url_string(&self) -> NSString {
56        unsafe { NSString::from_id(msg_send![self.m_self(), urlString]) }
57    }
58
59    /// The service’s user identifier associated with the social profile.
60    #[property]
61    pub fn user_identifier(&self) -> NSString {
62        unsafe { NSString::from_id(msg_send![self.m_self(), userIdentifier]) }
63    }
64
65    /* Getting Localized User Profile Information
66     */
67
68    /// Returns the localized name of the property for the specified key.
69    #[method]
70    pub fn localized_string_for_key(key: NSString) -> NSString {
71        unsafe { NSString::from_id(msg_send![Self::m_class(), localizedStringForKey: key]) }
72    }
73
74    /// Returns the localized name of the specified service.
75    #[method]
76    pub fn localized_string_for_service(service: NSString) -> NSString {
77        unsafe {
78            NSString::from_id(msg_send![
79                Self::m_class(),
80                localizedStringForService: service
81            ])
82        }
83    }
84}