objc2_contacts/generated/
CNContactFormatter.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// The formatting styles for contact names.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactformatterstyle?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct CNContactFormatterStyle(pub NSInteger);
17impl CNContactFormatterStyle {
18    /// Combine the contact name components into a displayable full name.
19    #[doc(alias = "CNContactFormatterStyleFullName")]
20    pub const FullName: Self = Self(0);
21    /// Combine the contact phonetic name components into a displayable phonetic full name.
22    #[doc(alias = "CNContactFormatterStylePhoneticFullName")]
23    pub const PhoneticFullName: Self = Self(1);
24}
25
26unsafe impl Encode for CNContactFormatterStyle {
27    const ENCODING: Encoding = NSInteger::ENCODING;
28}
29
30unsafe impl RefEncode for CNContactFormatterStyle {
31    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34/// The formatting order of the contact name components.
35///
36/// See also [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactdisplaynameorder?language=objc)
37// NS_ENUM
38#[repr(transparent)]
39#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
40pub struct CNContactDisplayNameOrder(pub NSInteger);
41impl CNContactDisplayNameOrder {
42    #[doc(alias = "CNContactDisplayNameOrderUserDefault")]
43    pub const UserDefault: Self = Self(0);
44    #[doc(alias = "CNContactDisplayNameOrderGivenNameFirst")]
45    pub const GivenNameFirst: Self = Self(1);
46    #[doc(alias = "CNContactDisplayNameOrderFamilyNameFirst")]
47    pub const FamilyNameFirst: Self = Self(2);
48}
49
50unsafe impl Encode for CNContactDisplayNameOrder {
51    const ENCODING: Encoding = NSInteger::ENCODING;
52}
53
54unsafe impl RefEncode for CNContactDisplayNameOrder {
55    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
56}
57
58extern_class!(
59    /// Formats a contact name.
60    ///
61    ///
62    /// This formatter handles international ordering and delimiting of the contact name components. This includes applying the user defaults when appropriate.
63    ///
64    /// See also [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactformatter?language=objc)
65    #[unsafe(super(NSFormatter, NSObject))]
66    #[derive(Debug, PartialEq, Eq, Hash)]
67    pub struct CNContactFormatter;
68);
69
70unsafe impl NSCoding for CNContactFormatter {}
71
72unsafe impl NSCopying for CNContactFormatter {}
73
74unsafe impl CopyingHelper for CNContactFormatter {
75    type Result = Self;
76}
77
78unsafe impl NSObjectProtocol for CNContactFormatter {}
79
80unsafe impl NSSecureCoding for CNContactFormatter {}
81
82impl CNContactFormatter {
83    extern_methods!(
84        #[cfg(feature = "CNContact")]
85        /// The contact key descriptor required for the formatter.
86        ///
87        ///
88        /// Use to fetch all contact keys required for the formatter style. Can combine key descriptors for different formatter styles in the fetch.
89        ///
90        ///
91        /// Parameter `style`: The formatting style to be used for the contact name.
92        ///
93        /// Returns: The contact key descriptor for the formatting style.
94        #[unsafe(method(descriptorForRequiredKeysForStyle:))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn descriptorForRequiredKeysForStyle(
97            style: CNContactFormatterStyle,
98        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;
99
100        #[cfg(feature = "CNContact")]
101        /// The contact key descriptor required for the name order.
102        ///
103        ///
104        /// Use to fetch all contact keys required for +nameOrderForContact:. Can combine key descriptors for different formatter styles in the fetch.
105        ///
106        ///
107        /// Returns: The contact key descriptor for the name order.
108        #[unsafe(method(descriptorForRequiredKeysForNameOrder))]
109        #[unsafe(method_family = none)]
110        pub unsafe fn descriptorForRequiredKeysForNameOrder(
111        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;
112
113        #[cfg(feature = "CNContact")]
114        /// The contact key descriptor required for the name delimiter.
115        ///
116        ///
117        /// Use to fetch all contact keys required for +delimiterForContact:. Can combine key descriptors for different formatter styles in the fetch.
118        ///
119        ///
120        /// Returns: The contact key descriptor for the name delimiter.
121        #[unsafe(method(descriptorForRequiredKeysForDelimiter))]
122        #[unsafe(method_family = none)]
123        pub unsafe fn descriptorForRequiredKeysForDelimiter(
124        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;
125
126        #[cfg(feature = "CNContact")]
127        /// Formats the contact name.
128        ///
129        ///
130        /// Parameter `contact`: The contact whose name is to be formatted.
131        ///
132        /// Parameter `style`: The formatting style to be used for the contact name.
133        ///
134        /// Returns: The formatted contact name.
135        #[unsafe(method(stringFromContact:style:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn stringFromContact_style(
138            contact: &CNContact,
139            style: CNContactFormatterStyle,
140        ) -> Option<Retained<NSString>>;
141
142        #[cfg(feature = "CNContact")]
143        /// Formats the contact name returning an attributed string.
144        ///
145        ///
146        /// This behaves like +stringFromContact:style: except it returns an attributed string. Includes the attribute key CNContactPropertyAttribute.
147        ///
148        ///
149        /// Parameter `contact`: The contact whose name is to be formatted.
150        ///
151        /// Parameter `style`: The formatting style to be used for the contact name.
152        ///
153        /// Parameter `attributes`: The default attributes to use. See NSFormatter for details.
154        ///
155        /// Returns: The formatted contact name as an attributed string.
156        #[unsafe(method(attributedStringFromContact:style:defaultAttributes:))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn attributedStringFromContact_style_defaultAttributes(
159            contact: &CNContact,
160            style: CNContactFormatterStyle,
161            attributes: Option<&NSDictionary>,
162        ) -> Option<Retained<NSAttributedString>>;
163
164        #[cfg(feature = "CNContact")]
165        /// The recommended name order for a given contact.
166        #[unsafe(method(nameOrderForContact:))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn nameOrderForContact(contact: &CNContact) -> CNContactDisplayNameOrder;
169
170        #[cfg(feature = "CNContact")]
171        /// The recommended delimiter to use between name components for a given contact.
172        #[unsafe(method(delimiterForContact:))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn delimiterForContact(contact: &CNContact) -> Retained<NSString>;
175
176        /// The style for a contact formatter instance.
177        ///
178        ///
179        /// The default value is CNContactFormatterStyleFullName.
180        #[unsafe(method(style))]
181        #[unsafe(method_family = none)]
182        pub unsafe fn style(&self) -> CNContactFormatterStyle;
183
184        /// Setter for [`style`][Self::style].
185        #[unsafe(method(setStyle:))]
186        #[unsafe(method_family = none)]
187        pub unsafe fn setStyle(&self, style: CNContactFormatterStyle);
188
189        #[cfg(feature = "CNContact")]
190        /// Formats the contact name.
191        ///
192        ///
193        /// Parameter `contact`: The contact whose name is to be formatted.
194        ///
195        /// Returns: The formatted contact name.
196        #[unsafe(method(stringFromContact:))]
197        #[unsafe(method_family = none)]
198        pub unsafe fn stringFromContact(&self, contact: &CNContact) -> Option<Retained<NSString>>;
199
200        #[cfg(feature = "CNContact")]
201        /// Formats the contact name returning an attributed string.
202        ///
203        ///
204        /// This behaves like -stringFromContact:style: except it returns an attributed string. CNContactPropertyAttribute key has the value of a CNContact name property key.
205        ///
206        ///
207        /// Parameter `contact`: The contact whose name is to be formatted.
208        ///
209        /// Parameter `attributes`: The default attributes to use. See NSFormatter for details.
210        ///
211        /// Returns: The formatted contact name as an attributed string.
212        #[unsafe(method(attributedStringFromContact:defaultAttributes:))]
213        #[unsafe(method_family = none)]
214        pub unsafe fn attributedStringFromContact_defaultAttributes(
215            &self,
216            contact: &CNContact,
217            attributes: Option<&NSDictionary>,
218        ) -> Option<Retained<NSAttributedString>>;
219    );
220}
221
222/// Methods declared on superclass `NSObject`.
223impl CNContactFormatter {
224    extern_methods!(
225        #[unsafe(method(init))]
226        #[unsafe(method_family = init)]
227        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
228
229        #[unsafe(method(new))]
230        #[unsafe(method_family = new)]
231        pub unsafe fn new() -> Retained<Self>;
232    );
233}
234
235extern "C" {
236    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactpropertyattribute?language=objc)
237    pub static CNContactPropertyAttribute: &'static NSString;
238}