rust_macios/contacts/
cn_contact_formatter.rs1use objc::{msg_send, sel, sel_impl};
2use rust_macios_objective_c_runtime_proc_macros::interface_impl;
3
4use crate::{
5 foundation::{INSFormatter, NSAttributedString, NSDictionary, NSString},
6 object,
7 objective_c_runtime::id,
8 utils::to_optional,
9};
10
11use super::CNContact;
12
13#[repr(i64)]
14pub enum CNContactFormatterStyle {
15 FullName,
17 PhoneticFullName,
19}
20
21#[repr(i64)]
22pub enum CNContactDisplayNameOrder {
23 CNContactDisplayNameOrderUserDefault,
24 CNContactDisplayNameOrderGivenNameFirst,
25 CNContactDisplayNameOrderFamilyNameFirst,
26}
27
28object! {
29 unsafe pub struct CNContactFormatter;
31}
32
33impl INSFormatter for CNContactFormatter {}
34
35#[interface_impl(NSFormatter)]
36impl CNContactFormatter {
37 #[method]
42 pub fn attributed_string_from_contact_default_attributes<K, V>(
43 &self,
44 contact: CNContact,
45 attributes: NSDictionary<K, V>,
46 ) -> Option<NSAttributedString> {
47 unsafe {
48 to_optional(
49 msg_send![self.m_self(), attributedStringFromContact: contact defaultAttributes: attributes],
50 )
51 }
52 }
53
54 #[method]
56 pub fn attributed_string_from_contact_style_default_attributes<K, V>(
57 contact: CNContact,
58 style: CNContactFormatterStyle,
59 attributes: NSDictionary<K, V>,
60 ) -> Option<NSAttributedString> {
61 unsafe {
62 to_optional(
63 msg_send![Self::m_class(), attributedStringFromContact: contact style: style defaultAttributes: attributes],
64 )
65 }
66 }
67
68 #[method]
70 pub fn string_from_contact(&self, contact: CNContact) -> Option<NSString> {
71 unsafe { to_optional(msg_send![self.m_self(), stringFromContact: contact]) }
72 }
73
74 #[method]
76 pub fn string_from_contact_style(
77 contact: CNContact,
78 style: CNContactFormatterStyle,
79 ) -> Option<NSString> {
80 unsafe { to_optional(msg_send![Self::m_class(), stringFromContact: contact style: style]) }
81 }
82
83 #[property]
88 pub fn style(&self) -> CNContactFormatterStyle {
89 unsafe { msg_send![self.m_self(), style] }
90 }
91
92 #[property]
94 pub fn set_style(&mut self) -> CNContactFormatterStyle {
95 unsafe { msg_send![self.m_self(), style] }
96 }
97
98 #[method]
103 pub fn descriptor_for_required_keys_for_style(style: CNContactFormatterStyle) -> id {
104 unsafe { msg_send![Self::m_class(), descriptorForRequiredKeysForStyle: style] }
105 }
106
107 #[method]
112 pub fn delimiter_for_contact(contact: CNContact) -> NSString {
113 unsafe { msg_send![Self::m_class(), delimiterForContact: contact] }
114 }
115
116 #[method]
118 pub fn name_order_for_contact(contact: CNContact) -> CNContactDisplayNameOrder {
119 unsafe { msg_send![Self::m_class(), nameOrderForContact: contact] }
120 }
121
122 #[property]
126 pub fn descriptor_for_required_keys_for_delimiter() -> id {
127 unsafe { msg_send![Self::m_class(), descriptorForRequiredKeysForDelimiter] }
128 }
129
130 #[property]
131 pub fn descriptor_for_required_keys_for_name_order() -> id {
132 unsafe { msg_send![Self::m_class(), descriptorForRequiredKeysForNameOrder] }
133 }
134}