rust_macios/contacts/
cn_postal_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 representation of the postal address for a contact.
14    unsafe pub struct CNPostalAddress;
15}
16
17#[interface_impl(NSObject)]
18impl CNPostalAddress {
19    /* Getting the Parts of a Postal Address
20     */
21
22    /// The street name in a postal address.
23    #[property]
24    pub fn street(&self) -> NSString {
25        unsafe { NSString::from_id(msg_send![self.m_self(), street]) }
26    }
27
28    /// The city name in a postal address.
29    #[property]
30    pub fn city(&self) -> NSString {
31        unsafe { NSString::from_id(msg_send![self.m_self(), city]) }
32    }
33
34    /// The state name in a postal address.
35    #[property]
36    pub fn state(&self) -> NSString {
37        unsafe { NSString::from_id(msg_send![self.m_self(), state]) }
38    }
39
40    /// The postal code in a postal address.
41    #[property]
42    pub fn postal_code(&self) -> NSString {
43        unsafe { NSString::from_id(msg_send![self.m_self(), postalCode]) }
44    }
45
46    /// The country or region name in a postal address.
47    #[property]
48    pub fn country(&self) -> NSString {
49        unsafe { NSString::from_id(msg_send![self.m_self(), country]) }
50    }
51
52    /// The ISO country code for the country or region in a postal address, using the ISO 3166-1 alpha-2 standard.
53    #[property]
54    pub fn iso_country_code(&self) -> NSString {
55        unsafe { NSString::from_id(msg_send![self.m_self(), ISOCountryCode]) }
56    }
57
58    /// The subadministrative area (such as a county or other region) in a postal address.
59    #[property]
60    pub fn sub_administrative_area(&self) -> NSString {
61        unsafe { NSString::from_id(msg_send![self.m_self(), subAdministrativeArea]) }
62    }
63
64    /// Additional information associated with the location, typically defined at the city or town level, in a postal address.
65    #[property]
66    pub fn sub_locality(&self) -> NSString {
67        unsafe { NSString::from_id(msg_send![self.m_self(), subLocality]) }
68    }
69
70    /* Getting Localized Postal Values
71     */
72
73    /// Returns the localized name for the property associated with the specified key.
74    pub fn localized_string_for_key(key: NSString) -> NSString {
75        unsafe { NSString::from_id(msg_send![self.m_self(), localizedStringForKey: key]) }
76    }
77}