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
70extern_conformance!(
71    unsafe impl NSCoding for CNContactFormatter {}
72);
73
74extern_conformance!(
75    unsafe impl NSCopying for CNContactFormatter {}
76);
77
78unsafe impl CopyingHelper for CNContactFormatter {
79    type Result = Self;
80}
81
82extern_conformance!(
83    unsafe impl NSObjectProtocol for CNContactFormatter {}
84);
85
86extern_conformance!(
87    unsafe impl NSSecureCoding for CNContactFormatter {}
88);
89
90impl CNContactFormatter {
91    extern_methods!(
92        #[cfg(feature = "CNContact")]
93        /// The contact key descriptor required for the formatter.
94        ///
95        ///
96        /// Use to fetch all contact keys required for the formatter style. Can combine key descriptors for different formatter styles in the fetch.
97        ///
98        ///
99        /// Parameter `style`: The formatting style to be used for the contact name.
100        ///
101        /// Returns: The contact key descriptor for the formatting style.
102        #[unsafe(method(descriptorForRequiredKeysForStyle:))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn descriptorForRequiredKeysForStyle(
105            style: CNContactFormatterStyle,
106        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;
107
108        #[cfg(feature = "CNContact")]
109        /// The contact key descriptor required for the name order.
110        ///
111        ///
112        /// Use to fetch all contact keys required for +nameOrderForContact:. Can combine key descriptors for different formatter styles in the fetch.
113        ///
114        ///
115        /// Returns: The contact key descriptor for the name order.
116        #[unsafe(method(descriptorForRequiredKeysForNameOrder))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn descriptorForRequiredKeysForNameOrder(
119        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;
120
121        #[cfg(feature = "CNContact")]
122        /// The contact key descriptor required for the name delimiter.
123        ///
124        ///
125        /// Use to fetch all contact keys required for +delimiterForContact:. Can combine key descriptors for different formatter styles in the fetch.
126        ///
127        ///
128        /// Returns: The contact key descriptor for the name delimiter.
129        #[unsafe(method(descriptorForRequiredKeysForDelimiter))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn descriptorForRequiredKeysForDelimiter(
132        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;
133
134        #[cfg(feature = "CNContact")]
135        /// Formats the contact name.
136        ///
137        ///
138        /// Parameter `contact`: The contact whose name is to be formatted.
139        ///
140        /// Parameter `style`: The formatting style to be used for the contact name.
141        ///
142        /// Returns: The formatted contact name.
143        #[unsafe(method(stringFromContact:style:))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn stringFromContact_style(
146            contact: &CNContact,
147            style: CNContactFormatterStyle,
148        ) -> Option<Retained<NSString>>;
149
150        #[cfg(feature = "CNContact")]
151        /// Formats the contact name returning an attributed string.
152        ///
153        ///
154        /// This behaves like +stringFromContact:style: except it returns an attributed string. Includes the attribute key CNContactPropertyAttribute.
155        ///
156        ///
157        /// Parameter `contact`: The contact whose name is to be formatted.
158        ///
159        /// Parameter `style`: The formatting style to be used for the contact name.
160        ///
161        /// Parameter `attributes`: The default attributes to use. See NSFormatter for details.
162        ///
163        /// Returns: The formatted contact name as an attributed string.
164        #[unsafe(method(attributedStringFromContact:style:defaultAttributes:))]
165        #[unsafe(method_family = none)]
166        pub unsafe fn attributedStringFromContact_style_defaultAttributes(
167            contact: &CNContact,
168            style: CNContactFormatterStyle,
169            attributes: Option<&NSDictionary>,
170        ) -> Option<Retained<NSAttributedString>>;
171
172        #[cfg(feature = "CNContact")]
173        /// The recommended name order for a given contact.
174        #[unsafe(method(nameOrderForContact:))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn nameOrderForContact(contact: &CNContact) -> CNContactDisplayNameOrder;
177
178        #[cfg(feature = "CNContact")]
179        /// The recommended delimiter to use between name components for a given contact.
180        #[unsafe(method(delimiterForContact:))]
181        #[unsafe(method_family = none)]
182        pub unsafe fn delimiterForContact(contact: &CNContact) -> Retained<NSString>;
183
184        /// The style for a contact formatter instance.
185        ///
186        ///
187        /// The default value is CNContactFormatterStyleFullName.
188        #[unsafe(method(style))]
189        #[unsafe(method_family = none)]
190        pub unsafe fn style(&self) -> CNContactFormatterStyle;
191
192        /// Setter for [`style`][Self::style].
193        #[unsafe(method(setStyle:))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn setStyle(&self, style: CNContactFormatterStyle);
196
197        #[cfg(feature = "CNContact")]
198        /// Formats the contact name.
199        ///
200        ///
201        /// Parameter `contact`: The contact whose name is to be formatted.
202        ///
203        /// Returns: The formatted contact name.
204        #[unsafe(method(stringFromContact:))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn stringFromContact(&self, contact: &CNContact) -> Option<Retained<NSString>>;
207
208        #[cfg(feature = "CNContact")]
209        /// Formats the contact name returning an attributed string.
210        ///
211        ///
212        /// This behaves like -stringFromContact:style: except it returns an attributed string. CNContactPropertyAttribute key has the value of a CNContact name property key.
213        ///
214        ///
215        /// Parameter `contact`: The contact whose name is to be formatted.
216        ///
217        /// Parameter `attributes`: The default attributes to use. See NSFormatter for details.
218        ///
219        /// Returns: The formatted contact name as an attributed string.
220        #[unsafe(method(attributedStringFromContact:defaultAttributes:))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn attributedStringFromContact_defaultAttributes(
223            &self,
224            contact: &CNContact,
225            attributes: Option<&NSDictionary>,
226        ) -> Option<Retained<NSAttributedString>>;
227    );
228}
229
230/// Methods declared on superclass `NSObject`.
231impl CNContactFormatter {
232    extern_methods!(
233        #[unsafe(method(init))]
234        #[unsafe(method_family = init)]
235        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
236
237        #[unsafe(method(new))]
238        #[unsafe(method_family = new)]
239        pub unsafe fn new() -> Retained<Self>;
240    );
241}
242
243extern "C" {
244    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactpropertyattribute?language=objc)
245    pub static CNContactPropertyAttribute: &'static NSString;
246}