rust_macios/contacts/
cn_mutable_contact.rs1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4 foundation::{NSArray, NSData, NSDateComponents, NSString},
5 object,
6 objective_c_runtime::macros::interface_impl,
7};
8
9use super::{
10 CNContactRelation, CNInstantMessageAddress, CNLabeledValue, CNPhoneNumber, CNSocialProfile,
11 ICNContact, ICNPostalAddress,
12};
13
14object! {
15 unsafe pub struct CNMutableContact;
17}
18
19impl ICNContact for CNMutableContact {}
20
21#[interface_impl(CNContact)]
22impl CNMutableContact {
23 #[property]
25 pub fn set_name_prefix(&mut self, name_prefix: NSString) {
26 unsafe { msg_send![self.m_self(), setNamePrefix: name_prefix] }
27 }
28
29 #[property]
31 pub fn set_given_name(&mut self, given_name: NSString) {
32 unsafe { msg_send![self.m_self(), setGivenName: given_name] }
33 }
34
35 #[property]
37 pub fn set_middle_name(&mut self, middle_name: NSString) {
38 unsafe { msg_send![self.m_self(), setMiddleName: middle_name] }
39 }
40
41 #[property]
43 pub fn set_family_name(&mut self, family_name: NSString) {
44 unsafe { msg_send![self.m_self(), setFamilyName: family_name] }
45 }
46
47 #[property]
49 pub fn set_previous_family_name(&mut self, previous_family_name: NSString) {
50 unsafe { msg_send![self.m_self(), setPreviousFamilyName: previous_family_name] }
51 }
52
53 #[property]
55 pub fn set_name_suffix(&mut self, name_suffix: NSString) {
56 unsafe { msg_send![self.m_self(), setNameSuffix: name_suffix] }
57 }
58
59 #[property]
61 pub fn set_nickname(&mut self, nickname: NSString) {
62 unsafe { msg_send![self.m_self(), setNickname: nickname] }
63 }
64
65 #[property]
67 pub fn set_phonetic_given_name(&mut self, phonetic_given_name: NSString) {
68 unsafe { msg_send![self.m_self(), setPhoneticGivenName: phonetic_given_name] }
69 }
70
71 #[property]
73 pub fn set_phonetic_middle_name(&mut self, phonetic_middle_name: NSString) {
74 unsafe { msg_send![self.m_self(), setPhoneticMiddleName: phonetic_middle_name] }
75 }
76
77 #[property]
79 pub fn set_phonetic_family_name(&mut self, phonetic_family_name: NSString) {
80 unsafe { msg_send![self.m_self(), setPhoneticFamilyName: phonetic_family_name] }
81 }
82
83 #[property]
88 pub fn set_job_title(&mut self, job_title: NSString) {
89 unsafe { msg_send![self.m_self(), setJobTitle: job_title] }
90 }
91
92 #[property]
94 pub fn set_department_name(&mut self, department_name: NSString) {
95 unsafe { msg_send![self.m_self(), setDepartmentName: department_name] }
96 }
97
98 #[property]
100 pub fn set_organization_name(&mut self, organization_name: NSString) {
101 unsafe { msg_send![self.m_self(), setOrganizationName: organization_name] }
102 }
103
104 #[property]
106 pub fn set_phonetic_organization_name(&mut self, phonetic_organization_name: NSString) {
107 unsafe {
108 msg_send![
109 self.m_self(),
110 setPhoneticOrganizationName: phonetic_organization_name
111 ]
112 }
113 }
114
115 #[property]
120 pub fn set_postal_addresses<PostalAddress>(
121 &mut self,
122 postal_addresses: NSArray<CNLabeledValue<PostalAddress>>,
123 ) where
124 PostalAddress: ICNPostalAddress,
125 {
126 unsafe { msg_send![self.m_self(), setPostalAddresses: postal_addresses] }
127 }
128
129 #[property]
131 pub fn set_email_addresses(&mut self, email_addresses: NSArray<CNLabeledValue<NSString>>) {
132 unsafe { msg_send![self.m_self(), setEmailAddresses: email_addresses] }
133 }
134
135 #[property]
137 pub fn set_url_addresses(&mut self, url_addresses: NSArray<CNLabeledValue<NSString>>) {
138 unsafe { msg_send![self.m_self(), setUrlAddresses: url_addresses] }
139 }
140
141 #[property]
146 pub fn set_phone_numbers(&mut self, phone_numbers: NSArray<CNLabeledValue<CNPhoneNumber>>) {
147 unsafe { msg_send![self.m_self(), setPhoneNumbers: phone_numbers] }
148 }
149
150 #[property]
155 pub fn set_social_profiles(
156 &mut self,
157 social_profiles: NSArray<CNLabeledValue<CNSocialProfile>>,
158 ) {
159 unsafe { msg_send![self.m_self(), setSocialProfiles: social_profiles] }
160 }
161
162 #[property]
167 pub fn set_dates(&mut self, dates: NSArray<CNLabeledValue<NSDateComponents>>) {
168 unsafe { msg_send![self.m_self(), setBirthdayDates: dates] }
169 }
170
171 #[property]
173 pub fn set_non_gregorian_birthday(&mut self, non_gregorian_birthday: NSDateComponents) {
174 unsafe {
175 msg_send![
176 self.m_self(),
177 setNonGregorianBirthday: non_gregorian_birthday
178 ]
179 }
180 }
181
182 #[property]
184 pub fn set_birthday(&mut self, birthday: NSDateComponents) {
185 unsafe { msg_send![self.m_self(), setBirthday: birthday] }
186 }
187
188 #[property]
193 pub fn set_note(&mut self, note: NSString) {
194 unsafe { msg_send![self.m_self(), setNote: note] }
195 }
196
197 #[property]
199 pub fn set_image_data(&mut self, image_data: NSData) {
200 unsafe { msg_send![self.m_self(), setImageData: image_data] }
201 }
202
203 #[property]
208 pub fn set_contact_relations(
209 &mut self,
210 contact_relations: NSArray<CNLabeledValue<CNContactRelation>>,
211 ) {
212 unsafe { msg_send![self.m_self(), setContactRelations: contact_relations] }
213 }
214
215 #[property]
217 pub fn set_instant_messenger_addresses(
218 &mut self,
219 instant_messenger_addresses: NSArray<CNLabeledValue<CNInstantMessageAddress>>,
220 ) {
221 unsafe {
222 msg_send![
223 self.m_self(),
224 setInstantMessageAddresses: instant_messenger_addresses
225 ]
226 }
227 }
228}
229
230#[cfg(test)]
231mod test {
232 use crate::{
233 contacts::{CNContactType, CNMutableContact, ICNContact},
234 objective_c_runtime::traits::PNSObject,
235 };
236
237 #[test]
238 fn test_mutable_contact() {
239 let contact = CNMutableContact::m_new();
240
241 assert!(contact.p_birthday().is_none());
242 assert!(contact.p_contact_relations().count() == 0);
243 assert!(contact.p_contact_type() == CNContactType::Person);
244 assert!(contact.p_dates().count() == 0);
245 assert!(contact.p_department_name() == "");
246 assert!(contact.p_email_addresses().count() == 0);
247 assert!(contact.p_family_name() == "");
248 assert!(contact.p_given_name() == "");
249 assert!(contact.p_identifier() != "");
250 assert!(contact.p_image_data().is_none());
251 assert!(!contact.p_image_data_available());
252 assert!(contact.p_instant_messaging_addresses().count() == 0);
253 assert!(contact.p_job_title() == "");
254 assert!(contact.p_middle_name() == "");
255 assert!(contact.p_name_prefix() == "");
256 assert!(contact.p_name_suffix() == "");
257 assert!(contact.p_nickname() == "");
258 assert!(contact.p_non_gregorian_birthday().is_none());
259 assert!(contact.p_note() == "");
260 assert!(contact.p_organization_name() == "");
261 assert!(contact.p_phone_numbers().count() == 0);
262 assert!(contact.p_phonetic_given_name() == "");
263 assert!(contact.p_phonetic_middle_name() == "");
264 assert!(contact.p_phonetic_family_name() == "");
265 assert!(contact.p_postal_addresses().count() == 0);
266 assert!(contact.p_previous_family_name() == "");
267 assert!(contact.p_social_profiles().count() == 0);
268 assert!(contact.p_thumbnail_image_data().is_none());
269 assert!(contact.p_url_addresses().count() == 0);
270 }
271}