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
use std::marker::{PhantomData, Sized};
use objc::{msg_send, sel, sel_impl};
use crate::{
foundation::NSString,
object,
objective_c_runtime::traits::{FromId, PNSObject},
};
object! {
/// An immutable object that combines a contact property value with a label that describes that property.
unsafe pub struct CNLabeledValue<ValueType> {
marker: PhantomData<ValueType>,
}
}
/// A trait containing all the methods for [`ICNLabeledValue`]"
pub trait ICNLabeledValue<ValueType>: PNSObject
where
ValueType: PNSObject + FromId,
{
/// Returns a new labeled value identifier.
fn m_init_with_label_value(&mut self, label: &NSString, value: ValueType) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(msg_send![
self.m_self(),
initWithLabel:label.m_self()
value:value
])
}
}
/// Returns a new labeled value identifier.
fn m_labeled_value_with_label_value(label: &NSString, value: ValueType) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(
msg_send![Self::m_class(), labeledValueWithLabel:label.m_self() value:value],
)
}
}
/* Getting the Label and Value
*/
/// The label for a contact property value.
fn p_label(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), label]) }
}
/// A contact property value.
fn p_value(&self) -> ValueType {
unsafe { ValueType::from_id(msg_send![self.m_self(), value]) }
}
/* Setting Labels and Values
*/
/// Returns a labeled value object with an existing value and identifier.
fn m_labeled_value_by_setting_label(&self, label: &NSString) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(msg_send![self.m_self(), labeledValueBySettingLabel: label.m_self()])
}
}
/// Returns a labeled value object with the specified label and value with the existing identifier.
fn m_labeled_value_by_setting_label_value(&self, label: &NSString, value: ValueType) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(msg_send![
self.m_self(),
labeledValueBySettingLabel:label.m_self()
value:value
])
}
}
/// Returns a new value for an existing label and identifier.
fn m_labeled_value_by_setting_value(&self, value: ValueType) -> Self
where
Self: Sized + FromId,
{
unsafe { Self::from_id(msg_send![self.m_self(), valueBySettingValue: value]) }
}
/* Localizing the Label and Value
*/
/// Returns a localized string for the specified label.
fn m_localized_string_for_label(label: &NSString) -> NSString {
unsafe {
NSString::from_id(msg_send![Self::m_class(), localizedStringForLabel: label.m_self()])
}
}
/// A unique identifier for the labeled value object.
fn p_identifier(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
}
}
impl<ValueType> ICNLabeledValue<ValueType> for CNLabeledValue<ValueType> where
ValueType: PNSObject + FromId
{
}
impl<ValueType> CNLabeledValue<ValueType>
where
ValueType: PNSObject + FromId,
{
/// Returns a new labeled value identifier.
pub fn init_with_label_value(&mut self, label: &NSString, value: ValueType) -> Self {
self.m_init_with_label_value(label, value)
}
/// Returns a new labeled value identifier.
pub fn labeled_value_with_label_value(label: &NSString, value: ValueType) -> Self {
Self::m_labeled_value_with_label_value(label, value)
}
/* Getting the Label and Value
*/
/// The label for a contact property value.
pub fn label(&self) -> NSString {
self.p_label()
}
/// A contact property value.
pub fn value(&self) -> ValueType {
self.p_value()
}
/* Setting Labels and Values
*/
/// Returns a labeled value object with an existing value and identifier.
pub fn labeled_value_by_setting_label(&self, label: &NSString) -> Self {
self.m_labeled_value_by_setting_label(label)
}
/// Returns a labeled value object with the specified label and value with the existing identifier.
pub fn labeled_value_by_setting_label_value(&self, label: &NSString, value: ValueType) -> Self {
self.m_labeled_value_by_setting_label_value(label, value)
}
/// Returns a new value for an existing label and identifier.
pub fn labeled_value_by_setting_value(&self, value: ValueType) -> Self {
self.m_labeled_value_by_setting_value(value)
}
/* Localizing the Label and Value
*/
/// Returns a localized string for the specified label.
pub fn localized_string_for_label(label: &NSString) -> NSString {
Self::m_localized_string_for_label(label)
}
/// A unique identifier for the labeled value object.
pub fn identifier(&self) -> NSString {
self.p_identifier()
}
}
extern "C" {
/* Getting Common Labels
*/
/// The label for identifying home information.
pub static CNLabelHome: NSString;
/// The label for identifying work information.
pub static CNLabelWork: NSString;
/// The label for the contact’s school.
pub static CNLabelSchool: NSString;
/// The label for identifying other information.
pub static CNLabelOther: NSString;
/// The label for identifying the contact's iCloud email information.
pub static CNLabelEmailiCloud: NSString;
/// The label for identifying URL information.
pub static CNLabelURLAddressHomePage: NSString;
/// The label for identifying the contact's anniversary date.
pub static CNLabelDateAnniversary: NSString;
}