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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
extern_class!(
/// An HKWorkoutBuilder is used to incrementally create new workouts in the HealthKit database. Samples,
/// events, and metadata may be added to a builder either during a live workout session or to create a
/// workout that occurred in the past. Calling finishWorkoutWithCompletion: will create a new workout
/// with samples, events, and metadata that have been provided.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/healthkit/hkworkoutbuilder?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct HKWorkoutBuilder;
);
unsafe impl Send for HKWorkoutBuilder {}
unsafe impl Sync for HKWorkoutBuilder {}
extern_conformance!(
unsafe impl NSObjectProtocol for HKWorkoutBuilder {}
);
impl HKWorkoutBuilder {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[cfg(feature = "HKDevice")]
/// The HKDevice to be associated with the workout.
#[unsafe(method(device))]
#[unsafe(method_family = none)]
pub unsafe fn device(&self) -> Option<Retained<HKDevice>>;
/// The start date for the workout, as provided by beginCollectionWithStartDate:completion:
#[unsafe(method(startDate))]
#[unsafe(method_family = none)]
pub unsafe fn startDate(&self) -> Option<Retained<NSDate>>;
/// The end date for the workout, as provided by endCollectionWithEndDate:completion:
#[unsafe(method(endDate))]
#[unsafe(method_family = none)]
pub unsafe fn endDate(&self) -> Option<Retained<NSDate>>;
#[cfg(feature = "HKWorkoutConfiguration")]
/// The configuration for the workout being built.
#[unsafe(method(workoutConfiguration))]
#[unsafe(method_family = none)]
pub unsafe fn workoutConfiguration(&self) -> Retained<HKWorkoutConfiguration>;
/// The metadata that will be used when the workout is finished.
#[unsafe(method(metadata))]
#[unsafe(method_family = none)]
pub unsafe fn metadata(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
#[cfg(feature = "HKWorkout")]
/// Workout events that have been added to the builder.
///
/// New events that are added using addWorkoutEvents:completion: will be appended to this array once the
/// completion is called.
#[unsafe(method(workoutEvents))]
#[unsafe(method_family = none)]
pub unsafe fn workoutEvents(&self) -> Retained<NSArray<HKWorkoutEvent>>;
#[cfg(feature = "HKWorkoutActivity")]
/// Workout activities that have been added to the builder.
///
/// New activities that are added using addWorkoutActivity:completion: will be appended to this array once the
/// completion is called.
#[unsafe(method(workoutActivities))]
#[unsafe(method_family = none)]
pub unsafe fn workoutActivities(&self) -> Retained<NSArray<HKWorkoutActivity>>;
#[cfg(all(feature = "HKObjectType", feature = "HKStatistics"))]
/// A dictionary of statistics per quantity type added to the builder
///
/// This dictionary will contain HKStatistics objects containing the statistics by quantity
/// sample type for all of the samples that have been added to the builder.
#[unsafe(method(allStatistics))]
#[unsafe(method_family = none)]
pub unsafe fn allStatistics(&self) -> Retained<NSDictionary<HKQuantityType, HKStatistics>>;
#[cfg(all(
feature = "HKDevice",
feature = "HKHealthStore",
feature = "HKWorkoutConfiguration"
))]
/// The designated initializer to create an HKWorkoutBuilder.
///
/// Creates a new HKWorkoutBuilder unconnected to any HKWorkoutSession or any sources of data.
///
///
/// Parameter `healthStore`: Specifies the HKHealthStore object to use for building the workout. The store is retained
/// until the builder is finished and a workout has been saved or discarded.
///
/// Parameter `configuration`: The workout configuration to be used.
///
/// Parameter `device`: The HKDevice to attach to the resulting HKWorkout.
#[unsafe(method(initWithHealthStore:configuration:device:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithHealthStore_configuration_device(
this: Allocated<Self>,
health_store: &HKHealthStore,
configuration: &HKWorkoutConfiguration,
device: Option<&HKDevice>,
) -> Retained<Self>;
#[cfg(feature = "block2")]
/// Sets the workout start date and activates the workout builder.
///
/// Calling this method is required before any samples, events or metadata can be added to the builder.
///
///
/// Parameter `startDate`: The start date of the workout.
///
/// Parameter `completion`: Called once data collection has started or has failed to start.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(beginCollectionWithStartDate:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn beginCollectionWithStartDate_completion(
&self,
start_date: &NSDate,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(all(feature = "HKObject", feature = "HKSample", feature = "block2"))]
/// Adds new samples to the builder instance. This method can be called multiple times to add samples
/// incrementally to the builder. The samples will be saved to the database if they have not already been
/// saved. The constraints of -[HKHealthStore saveObject:withCompletion:] apply to this method as well.
/// The start date of the samples must be later than the start date of the receiver. It is an error to call
/// this method after finishWorkoutWithCompletion: has been called. This operation is performed
/// asynchronously and the completion will be executed on an arbitrary background queue.
///
///
/// Parameter `samples`: The samples to add to the workout.
///
/// Parameter `completion`: Block to be called when the insertion is complete. If success is YES, the samples were added
/// to the builder successfully. If success is NO, error will be non-nil and contain the error
/// encountered while adding the new samples.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(addSamples:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn addSamples_completion(
&self,
samples: &NSArray<HKSample>,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(all(feature = "HKWorkout", feature = "block2"))]
/// Adds new workout events to the builder instance. This method can be called many times to add workout
/// events incrementally to the builder. It is an error to call this method after
/// finishWorkoutWithCompletion: has been called. This operation is performed asynchronously and the
/// completion will be executed on an arbitrary background queue.
///
///
/// Parameter `workoutEvents`: The events to add to the builder.
///
/// Parameter `completion`: Block to be called when the addition of events to the builder is complete. If success is
/// YES, the events were added to the builder successfully. If success is NO, error will be
/// non-null and will contain the error encountered during the insertion operation.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(addWorkoutEvents:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn addWorkoutEvents_completion(
&self,
workout_events: &NSArray<HKWorkoutEvent>,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "block2")]
/// Adds new metadata to the builder instance. This method can be called more than once; each time the newly
/// provided metadata will be merged with previously added metadata in the same manner as
/// -[NSMutableDictionary addEntriesFromDictionary:]. This operation is performed asynchronously and the
/// completion will be executed on an arbitrary background queue.
///
///
/// Parameter `metadata`: The metadata to add to the workout.
///
/// Parameter `completion`: Block to be called when the addition of metadata to the builder is complete. If success is
/// YES, the metadata has been added to the builder successfully. If success is NO, error will
/// be non-null and will contain the error encountered during the insertion operation. When an
/// error occurs, the builder's metadata property will remain unchanged.
///
/// # Safety
///
/// - `metadata` generic should be of the correct type.
/// - `completion` block must be sendable.
#[unsafe(method(addMetadata:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn addMetadata_completion(
&self,
metadata: &NSDictionary<NSString, AnyObject>,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(all(feature = "HKWorkoutActivity", feature = "block2"))]
/// Adds a new workout activity to the builder instance. This method can be called many times to add workout
/// activities incrementally to the builder. It is an error to call this method after
/// finishWorkoutWithCompletion: has been called. This operation is performed asynchronously and the
/// completion will be executed on an arbitrary background queue.
///
///
/// Parameter `workoutActivity`: The activity to add to the builder.
///
/// Parameter `completion`: Block to be called when the addition of the activity to the builder is complete. If success is
/// YES, the activity was added to the builder successfully. If success is NO, error will be
/// non-null and will contain the error encountered during the insertion operation.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(addWorkoutActivity:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn addWorkoutActivity_completion(
&self,
workout_activity: &HKWorkoutActivity,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "block2")]
/// Sets the end date on an already added activity. It is an error to call this method after
/// finishWorkoutWithCompletion: has been called. This operation is performed asynchronously and the
/// completion will be executed on an arbitrary background queue.
///
///
/// Parameter `UUID`: The UUID of the workout activity to update.
///
/// Parameter `endDate`: The end date to set on the activity
///
/// Parameter `completion`: Block to be called when the update of the end date on the activity is complete. If success is
/// YES, the end date was set to the actvity successfully. If success is NO, error will be
/// non-null and will contain the error encountered during the update operation.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(updateActivityWithUUID:endDate:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn updateActivityWithUUID_endDate_completion(
&self,
uuid: &NSUUID,
end_date: &NSDate,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "block2")]
/// Adds new metadata to an already added activity. This method can be called more than once; each time
/// the newly provided metadata will be merged with previously added metadata in the same manner as
/// -[NSMutableDictionary addEntriesFromDictionary:]. It is an error to call this method after
/// finishWorkoutWithCompletion: has been called. This operation is performed asynchronously and the
/// completion will be executed on an arbitrary background queue.
///
///
/// Parameter `UUID`: The UUID of the workout activity to update.
///
/// Parameter `metadata`: The metadata to add to the workout activity.
///
/// Parameter `completion`: Block to be called when the addition of metadata to the activity is complete. If success is
/// YES, the metadata has been added to the activity successfully. If success is NO, error will
/// be non-null and will contain the error encountered during the insertion operation. When an
/// error occurs, the activity's metadata property will remain unchanged.
///
/// # Safety
///
/// - `metadata` generic should be of the correct type.
/// - `completion` block must be sendable.
#[unsafe(method(updateActivityWithUUID:addMedatata:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn updateActivityWithUUID_addMedatata_completion(
&self,
uuid: &NSUUID,
metadata: &NSDictionary<NSString, AnyObject>,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "block2")]
/// Sets the workout end date and deactivates the workout builer.
///
/// Calling this method is required before you finish a workout builder.
///
///
/// Parameter `endDate`: The end date of the workout.
///
/// Parameter `completion`: Called once data collection has stopped or has failed to stop.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(endCollectionWithEndDate:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn endCollectionWithEndDate_completion(
&self,
end_date: &NSDate,
completion: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(all(
feature = "HKObject",
feature = "HKSample",
feature = "HKWorkout",
feature = "block2"
))]
/// Creates and saves an HKWorkout using samples and events that have been added to workout previously.
///
///
/// Parameter `completion`: Block to be called after the HKWorkout object has been created and saved. If the returned
/// workout is nil, an error may have occurred in which case error will be non-nil. If both
/// workout and error are nil then finishing the workout succeeded but the workout sample
/// is not available because the device is locked.
///
/// # Safety
///
/// `completion` block must be sendable.
#[unsafe(method(finishWorkoutWithCompletion:))]
#[unsafe(method_family = none)]
pub unsafe fn finishWorkoutWithCompletion(
&self,
completion: &block2::DynBlock<dyn Fn(*mut HKWorkout, *mut NSError)>,
);
/// Finishes building the workout and discards the result instead of saving it. Samples that were added to
/// the workout will not be deleted. Adding samples, events, and metadata to the receiver after
/// discardWorkout has been called is an error.
#[unsafe(method(discardWorkout))]
#[unsafe(method_family = none)]
pub unsafe fn discardWorkout(&self);
/// The elapsed duration of the workout evaluated at the specified date. The duration does not include
/// periods when the workout was paused, which are the intervals between pause and resume events.
#[unsafe(method(elapsedTimeAtDate:))]
#[unsafe(method_family = none)]
pub unsafe fn elapsedTimeAtDate(&self, date: &NSDate) -> NSTimeInterval;
#[cfg(all(feature = "HKObjectType", feature = "HKStatistics"))]
/// Returns an HKStatistics object containing the statistics for all the samples of the given type that
/// have been added to the receiver. If there are no samples of the given type then nil is returned.
///
///
/// Parameter `quantityType`: The quantity type to gather statistics about.
#[unsafe(method(statisticsForType:))]
#[unsafe(method_family = none)]
pub unsafe fn statisticsForType(
&self,
quantity_type: &HKQuantityType,
) -> Option<Retained<HKStatistics>>;
#[cfg(all(feature = "HKObjectType", feature = "HKSeriesBuilder"))]
/// Retrieves the associated series builder for the specified type.
///
/// Retrieves, and creates if it does not already exist, the series builder for the specified type. The
/// series constructed with the returned builder will be associated with the workout when it is finished.
///
///
/// Parameter `seriesType`: The series type for which the builder should be retrieved.
#[unsafe(method(seriesBuilderForType:))]
#[unsafe(method_family = none)]
pub unsafe fn seriesBuilderForType(
&self,
series_type: &HKSeriesType,
) -> Option<Retained<HKSeriesBuilder>>;
);
}
/// Methods declared on superclass `NSObject`.
impl HKWorkoutBuilder {
extern_methods!(
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}