objc2-contacts 0.3.2

Bindings to the Contacts framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontacttype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CNContactType(pub NSInteger);
impl CNContactType {
    #[doc(alias = "CNContactTypePerson")]
    pub const Person: Self = Self(0);
    #[doc(alias = "CNContactTypeOrganization")]
    pub const Organization: Self = Self(1);
}

unsafe impl Encode for CNContactType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for CNContactType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Sort order for contacts.
///
///
/// CNContactSortOrderUserDefault is the user's preferred sort order.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactsortorder?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CNContactSortOrder(pub NSInteger);
impl CNContactSortOrder {
    #[doc(alias = "CNContactSortOrderNone")]
    pub const None: Self = Self(0);
    #[doc(alias = "CNContactSortOrderUserDefault")]
    pub const UserDefault: Self = Self(1);
    #[doc(alias = "CNContactSortOrderGivenName")]
    pub const GivenName: Self = Self(2);
    #[doc(alias = "CNContactSortOrderFamilyName")]
    pub const FamilyName: Self = Self(3);
}

unsafe impl Encode for CNContactSortOrder {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for CNContactSortOrder {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// This protocol is reserved for Contacts framework usage.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/contacts/cnkeydescriptor?language=objc)
    pub unsafe trait CNKeyDescriptor: NSObjectProtocol + NSSecureCoding + NSCopying {}
);

extern_conformance!(
    unsafe impl CNKeyDescriptor for NSString {}
);

extern_class!(
    /// An immutable value object representing a contact.
    ///
    ///
    /// CNContact is thread safe.
    ///
    /// If using a CNContact instance where you are not certain of the keys that were fetched, use isKeyAvailable: or areKeysAvailable:. If these return NO you need to refetch the contact by the contact identifier with the keys you want to fetch. Accessing a property that was not fetched will throw CNContactPropertyNotFetchedExceptionName.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontact?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CNContact;
);

extern_conformance!(
    unsafe impl NSCoding for CNContact {}
);

extern_conformance!(
    unsafe impl NSCopying for CNContact {}
);

unsafe impl CopyingHelper for CNContact {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSMutableCopying for CNContact {}
);

#[cfg(feature = "CNMutableContact")]
unsafe impl MutableCopyingHelper for CNContact {
    type Result = CNMutableContact;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for CNContact {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for CNContact {}
);

impl CNContact {
    extern_methods!(
        /// The identifier is unique among contacts on the device. It can be saved and used for fetching contacts next application launch.
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifier(&self) -> Retained<NSString>;

        #[unsafe(method(contactType))]
        #[unsafe(method_family = none)]
        pub unsafe fn contactType(&self) -> CNContactType;

        #[unsafe(method(namePrefix))]
        #[unsafe(method_family = none)]
        pub unsafe fn namePrefix(&self) -> Retained<NSString>;

        #[unsafe(method(givenName))]
        #[unsafe(method_family = none)]
        pub unsafe fn givenName(&self) -> Retained<NSString>;

        #[unsafe(method(middleName))]
        #[unsafe(method_family = none)]
        pub unsafe fn middleName(&self) -> Retained<NSString>;

        #[unsafe(method(familyName))]
        #[unsafe(method_family = none)]
        pub unsafe fn familyName(&self) -> Retained<NSString>;

        #[unsafe(method(previousFamilyName))]
        #[unsafe(method_family = none)]
        pub unsafe fn previousFamilyName(&self) -> Retained<NSString>;

        #[unsafe(method(nameSuffix))]
        #[unsafe(method_family = none)]
        pub unsafe fn nameSuffix(&self) -> Retained<NSString>;

        #[unsafe(method(nickname))]
        #[unsafe(method_family = none)]
        pub unsafe fn nickname(&self) -> Retained<NSString>;

        #[unsafe(method(organizationName))]
        #[unsafe(method_family = none)]
        pub unsafe fn organizationName(&self) -> Retained<NSString>;

        #[unsafe(method(departmentName))]
        #[unsafe(method_family = none)]
        pub unsafe fn departmentName(&self) -> Retained<NSString>;

        #[unsafe(method(jobTitle))]
        #[unsafe(method_family = none)]
        pub unsafe fn jobTitle(&self) -> Retained<NSString>;

        #[unsafe(method(phoneticGivenName))]
        #[unsafe(method_family = none)]
        pub unsafe fn phoneticGivenName(&self) -> Retained<NSString>;

        #[unsafe(method(phoneticMiddleName))]
        #[unsafe(method_family = none)]
        pub unsafe fn phoneticMiddleName(&self) -> Retained<NSString>;

        #[unsafe(method(phoneticFamilyName))]
        #[unsafe(method_family = none)]
        pub unsafe fn phoneticFamilyName(&self) -> Retained<NSString>;

        #[unsafe(method(phoneticOrganizationName))]
        #[unsafe(method_family = none)]
        pub unsafe fn phoneticOrganizationName(&self) -> Retained<NSString>;

        #[unsafe(method(note))]
        #[unsafe(method_family = none)]
        pub unsafe fn note(&self) -> Retained<NSString>;

        #[unsafe(method(imageData))]
        #[unsafe(method_family = none)]
        pub unsafe fn imageData(&self) -> Option<Retained<NSData>>;

        #[unsafe(method(thumbnailImageData))]
        #[unsafe(method_family = none)]
        pub unsafe fn thumbnailImageData(&self) -> Option<Retained<NSData>>;

        #[unsafe(method(imageDataAvailable))]
        #[unsafe(method_family = none)]
        pub unsafe fn imageDataAvailable(&self) -> bool;

        #[cfg(all(feature = "CNLabeledValue", feature = "CNPhoneNumber"))]
        #[unsafe(method(phoneNumbers))]
        #[unsafe(method_family = none)]
        pub unsafe fn phoneNumbers(&self) -> Retained<NSArray<CNLabeledValue<CNPhoneNumber>>>;

        #[cfg(feature = "CNLabeledValue")]
        #[unsafe(method(emailAddresses))]
        #[unsafe(method_family = none)]
        pub unsafe fn emailAddresses(&self) -> Retained<NSArray<CNLabeledValue<NSString>>>;

        #[cfg(all(feature = "CNLabeledValue", feature = "CNPostalAddress"))]
        #[unsafe(method(postalAddresses))]
        #[unsafe(method_family = none)]
        pub unsafe fn postalAddresses(&self) -> Retained<NSArray<CNLabeledValue<CNPostalAddress>>>;

        #[cfg(feature = "CNLabeledValue")]
        #[unsafe(method(urlAddresses))]
        #[unsafe(method_family = none)]
        pub unsafe fn urlAddresses(&self) -> Retained<NSArray<CNLabeledValue<NSString>>>;

        #[cfg(all(feature = "CNContactRelation", feature = "CNLabeledValue"))]
        #[unsafe(method(contactRelations))]
        #[unsafe(method_family = none)]
        pub unsafe fn contactRelations(
            &self,
        ) -> Retained<NSArray<CNLabeledValue<CNContactRelation>>>;

        #[cfg(all(feature = "CNLabeledValue", feature = "CNSocialProfile"))]
        #[unsafe(method(socialProfiles))]
        #[unsafe(method_family = none)]
        pub unsafe fn socialProfiles(&self) -> Retained<NSArray<CNLabeledValue<CNSocialProfile>>>;

        #[cfg(all(feature = "CNInstantMessageAddress", feature = "CNLabeledValue"))]
        #[unsafe(method(instantMessageAddresses))]
        #[unsafe(method_family = none)]
        pub unsafe fn instantMessageAddresses(
            &self,
        ) -> Retained<NSArray<CNLabeledValue<CNInstantMessageAddress>>>;

        /// The Gregorian birthday.
        #[unsafe(method(birthday))]
        #[unsafe(method_family = none)]
        pub unsafe fn birthday(&self) -> Option<Retained<NSDateComponents>>;

        /// The alternate birthday (Lunisolar).
        #[unsafe(method(nonGregorianBirthday))]
        #[unsafe(method_family = none)]
        pub unsafe fn nonGregorianBirthday(&self) -> Option<Retained<NSDateComponents>>;

        #[cfg(feature = "CNLabeledValue")]
        /// Other Gregorian dates (anniversaries, etc).
        #[unsafe(method(dates))]
        #[unsafe(method_family = none)]
        pub unsafe fn dates(&self) -> Retained<NSArray<CNLabeledValue<NSDateComponents>>>;

        /// Returns YES if the value for the specified key was fetched.
        #[unsafe(method(isKeyAvailable:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isKeyAvailable(&self, key: &NSString) -> bool;

        /// Returns YES if the values for the keys specified by all the descriptors were fetched.
        #[unsafe(method(areKeysAvailable:))]
        #[unsafe(method_family = none)]
        pub unsafe fn areKeysAvailable(
            &self,
            key_descriptors: &NSArray<ProtocolObject<dyn CNKeyDescriptor>>,
        ) -> bool;

        /// Returns a user displayable property name.
        #[unsafe(method(localizedStringForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn localizedStringForKey(key: &NSString) -> Retained<NSString>;

        /// The contact comparator for a given sort order.
        ///
        /// # Safety
        ///
        /// - The returned block's argument 1 must be a valid pointer.
        /// - The returned block's argument 2 must be a valid pointer.
        #[unsafe(method(comparatorForNameSortOrder:))]
        #[unsafe(method_family = none)]
        pub unsafe fn comparatorForNameSortOrder(sort_order: CNContactSortOrder) -> NSComparator;

        /// Use to fetch all contact keys required for the contact sort comparator.
        #[unsafe(method(descriptorForAllComparatorKeys))]
        #[unsafe(method_family = none)]
        pub unsafe fn descriptorForAllComparatorKeys(
        ) -> Retained<ProtocolObject<dyn CNKeyDescriptor>>;

        /// Returns YES if the receiver was fetched as a unified contact and includes the contact having contactIdentifier in its unification
        #[unsafe(method(isUnifiedWithContactWithIdentifier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isUnifiedWithContactWithIdentifier(
            &self,
            contact_identifier: &NSString,
        ) -> bool;
    );
}

/// Methods declared on superclass `NSObject`.
impl CNContact {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactpropertynotfetchedexceptionname?language=objc)
    pub static CNContactPropertyNotFetchedExceptionName: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactidentifierkey?language=objc)
    pub static CNContactIdentifierKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactnameprefixkey?language=objc)
    pub static CNContactNamePrefixKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactgivennamekey?language=objc)
    pub static CNContactGivenNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactmiddlenamekey?language=objc)
    pub static CNContactMiddleNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactfamilynamekey?language=objc)
    pub static CNContactFamilyNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactpreviousfamilynamekey?language=objc)
    pub static CNContactPreviousFamilyNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactnamesuffixkey?language=objc)
    pub static CNContactNameSuffixKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactnicknamekey?language=objc)
    pub static CNContactNicknameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactorganizationnamekey?language=objc)
    pub static CNContactOrganizationNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactdepartmentnamekey?language=objc)
    pub static CNContactDepartmentNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactjobtitlekey?language=objc)
    pub static CNContactJobTitleKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactphoneticgivennamekey?language=objc)
    pub static CNContactPhoneticGivenNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactphoneticmiddlenamekey?language=objc)
    pub static CNContactPhoneticMiddleNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactphoneticfamilynamekey?language=objc)
    pub static CNContactPhoneticFamilyNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactphoneticorganizationnamekey?language=objc)
    pub static CNContactPhoneticOrganizationNameKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactbirthdaykey?language=objc)
    pub static CNContactBirthdayKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactnongregorianbirthdaykey?language=objc)
    pub static CNContactNonGregorianBirthdayKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactnotekey?language=objc)
    pub static CNContactNoteKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactimagedatakey?language=objc)
    pub static CNContactImageDataKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactthumbnailimagedatakey?language=objc)
    pub static CNContactThumbnailImageDataKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactimagedataavailablekey?language=objc)
    pub static CNContactImageDataAvailableKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontacttypekey?language=objc)
    pub static CNContactTypeKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactphonenumberskey?language=objc)
    pub static CNContactPhoneNumbersKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactemailaddresseskey?language=objc)
    pub static CNContactEmailAddressesKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactpostaladdresseskey?language=objc)
    pub static CNContactPostalAddressesKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactdateskey?language=objc)
    pub static CNContactDatesKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontacturladdresseskey?language=objc)
    pub static CNContactUrlAddressesKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactrelationskey?language=objc)
    pub static CNContactRelationsKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactsocialprofileskey?language=objc)
    pub static CNContactSocialProfilesKey: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/contacts/cncontactinstantmessageaddresseskey?language=objc)
    pub static CNContactInstantMessageAddressesKey: &'static NSString;
}