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        ///
165        /// # Safety
166        ///
167        /// `attributes` generic should be of the correct type.
168        #[unsafe(method(attributedStringFromContact:style:defaultAttributes:))]
169        #[unsafe(method_family = none)]
170        pub unsafe fn attributedStringFromContact_style_defaultAttributes(
171            contact: &CNContact,
172            style: CNContactFormatterStyle,
173            attributes: Option<&NSDictionary>,
174        ) -> Option<Retained<NSAttributedString>>;
175
176        #[cfg(feature = "CNContact")]
177        /// The recommended name order for a given contact.
178        #[unsafe(method(nameOrderForContact:))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn nameOrderForContact(contact: &CNContact) -> CNContactDisplayNameOrder;
181
182        #[cfg(feature = "CNContact")]
183        /// The recommended delimiter to use between name components for a given contact.
184        #[unsafe(method(delimiterForContact:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn delimiterForContact(contact: &CNContact) -> Retained<NSString>;
187
188        /// The style for a contact formatter instance.
189        ///
190        ///
191        /// The default value is CNContactFormatterStyleFullName.
192        #[unsafe(method(style))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn style(&self) -> CNContactFormatterStyle;
195
196        /// Setter for [`style`][Self::style].
197        #[unsafe(method(setStyle:))]
198        #[unsafe(method_family = none)]
199        pub unsafe fn setStyle(&self, style: CNContactFormatterStyle);
200
201        #[cfg(feature = "CNContact")]
202        /// Formats the contact name.
203        ///
204        ///
205        /// Parameter `contact`: The contact whose name is to be formatted.
206        ///
207        /// Returns: The formatted contact name.
208        #[unsafe(method(stringFromContact:))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn stringFromContact(&self, contact: &CNContact) -> Option<Retained<NSString>>;
211
212        #[cfg(feature = "CNContact")]
213        /// Formats the contact name returning an attributed string.
214        ///
215        ///
216        /// This behaves like -stringFromContact:style: except it returns an attributed string. CNContactPropertyAttribute key has the value of a CNContact name property key.
217        ///
218        ///
219        /// Parameter `contact`: The contact whose name is to be formatted.
220        ///
221        /// Parameter `attributes`: The default attributes to use. See NSFormatter for details.
222        ///
223        /// Returns: The formatted contact name as an attributed string.
224        ///
225        /// # Safety
226        ///
227        /// `attributes` generic should be of the correct type.
228        #[unsafe(method(attributedStringFromContact:defaultAttributes:))]
229        #[unsafe(method_family = none)]
230        pub unsafe fn attributedStringFromContact_defaultAttributes(
231            &self,
232            contact: &CNContact,
233            attributes: Option<&NSDictionary>,
234        ) -> Option<Retained<NSAttributedString>>;
235    );
236}
237
238/// Methods declared on superclass `NSObject`.
239impl CNContactFormatter {
240    extern_methods!(
241        #[unsafe(method(init))]
242        #[unsafe(method_family = init)]
243        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
244
245        #[unsafe(method(new))]
246        #[unsafe(method_family = new)]
247        pub unsafe fn new() -> Retained<Self>;
248    );
249}
250
251extern "C" {
252    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactpropertyattribute?language=objc)
253    pub static CNContactPropertyAttribute: &'static NSString;
254}