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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern "C" {
    pub static NSManagedObjectContextWillSaveNotification: &'static NSString;
}

extern "C" {
    pub static NSManagedObjectContextDidSaveNotification: &'static NSString;
}

extern "C" {
    pub static NSManagedObjectContextObjectsDidChangeNotification: &'static NSString;
}

extern "C" {
    pub static NSManagedObjectContextDidSaveObjectIDsNotification: &'static NSString;
}

extern "C" {
    pub static NSManagedObjectContextDidMergeChangesObjectIDsNotification: &'static NSString;
}

extern "C" {
    pub static NSInsertedObjectsKey: &'static NSString;
}

extern "C" {
    pub static NSUpdatedObjectsKey: &'static NSString;
}

extern "C" {
    pub static NSDeletedObjectsKey: &'static NSString;
}

extern "C" {
    pub static NSRefreshedObjectsKey: &'static NSString;
}

extern "C" {
    pub static NSInvalidatedObjectsKey: &'static NSString;
}

extern "C" {
    pub static NSManagedObjectContextQueryGenerationKey: &'static NSString;
}

extern "C" {
    pub static NSInvalidatedAllObjectsKey: &'static NSString;
}

extern "C" {
    pub static NSInsertedObjectIDsKey: &'static NSString;
}

extern "C" {
    pub static NSUpdatedObjectIDsKey: &'static NSString;
}

extern "C" {
    pub static NSDeletedObjectIDsKey: &'static NSString;
}

extern "C" {
    pub static NSRefreshedObjectIDsKey: &'static NSString;
}

extern "C" {
    pub static NSInvalidatedObjectIDsKey: &'static NSString;
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSManagedObjectContextConcurrencyType(pub NSUInteger);
impl NSManagedObjectContextConcurrencyType {
    #[deprecated = "Use another NSManagedObjectContextConcurrencyType"]
    pub const NSConfinementConcurrencyType: Self = Self(0x00);
    pub const NSPrivateQueueConcurrencyType: Self = Self(0x01);
    pub const NSMainQueueConcurrencyType: Self = Self(0x02);
}

unsafe impl Encode for NSManagedObjectContextConcurrencyType {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

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

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSManagedObjectContext;

    unsafe impl ClassType for NSManagedObjectContext {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

unsafe impl NSCoding for NSManagedObjectContext {}

unsafe impl NSLocking for NSManagedObjectContext {}

unsafe impl NSObjectProtocol for NSManagedObjectContext {}

extern_methods!(
    unsafe impl NSManagedObjectContext {
        #[deprecated = "Use -initWithConcurrencyType: instead"]
        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Retained<Self>;

        #[deprecated = "Use -initWithConcurrencyType: instead"]
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics Init initWithConcurrencyType:)]
        pub unsafe fn initWithConcurrencyType(
            this: Allocated<Self>,
            ct: NSManagedObjectContextConcurrencyType,
        ) -> Retained<Self>;

        #[cfg(feature = "block2")]
        #[method(performBlock:)]
        pub unsafe fn performBlock(&self, block: &block2::Block<dyn Fn()>);

        #[cfg(feature = "block2")]
        #[method(performBlockAndWait:)]
        pub unsafe fn performBlockAndWait(&self, block: &block2::Block<dyn Fn() + '_>);

        #[cfg(feature = "NSPersistentStoreCoordinator")]
        #[method_id(@__retain_semantics Other persistentStoreCoordinator)]
        pub unsafe fn persistentStoreCoordinator(
            &self,
        ) -> Option<Retained<NSPersistentStoreCoordinator>>;

        #[cfg(feature = "NSPersistentStoreCoordinator")]
        #[method(setPersistentStoreCoordinator:)]
        pub unsafe fn setPersistentStoreCoordinator(
            &self,
            persistent_store_coordinator: Option<&NSPersistentStoreCoordinator>,
        );

        #[method_id(@__retain_semantics Other parentContext)]
        pub unsafe fn parentContext(&self) -> Option<Retained<NSManagedObjectContext>>;

        #[method(setParentContext:)]
        pub unsafe fn setParentContext(&self, parent_context: Option<&NSManagedObjectContext>);

        #[method_id(@__retain_semantics Other name)]
        pub unsafe fn name(&self) -> Option<Retained<NSString>>;

        #[method(setName:)]
        pub unsafe fn setName(&self, name: Option<&NSString>);

        #[method_id(@__retain_semantics Other undoManager)]
        pub unsafe fn undoManager(&self) -> Option<Retained<NSUndoManager>>;

        #[method(setUndoManager:)]
        pub unsafe fn setUndoManager(&self, undo_manager: Option<&NSUndoManager>);

        #[method(hasChanges)]
        pub unsafe fn hasChanges(&self) -> bool;

        #[method_id(@__retain_semantics Other userInfo)]
        pub unsafe fn userInfo(&self) -> Retained<NSMutableDictionary>;

        #[method(concurrencyType)]
        pub unsafe fn concurrencyType(&self) -> NSManagedObjectContextConcurrencyType;

        #[cfg(all(feature = "NSManagedObject", feature = "NSManagedObjectID"))]
        #[method_id(@__retain_semantics Other objectRegisteredForID:)]
        pub unsafe fn objectRegisteredForID(
            &self,
            object_id: &NSManagedObjectID,
        ) -> Option<Retained<NSManagedObject>>;

        #[cfg(all(feature = "NSManagedObject", feature = "NSManagedObjectID"))]
        #[method_id(@__retain_semantics Other objectWithID:)]
        pub unsafe fn objectWithID(
            &self,
            object_id: &NSManagedObjectID,
        ) -> Retained<NSManagedObject>;

        #[cfg(all(feature = "NSManagedObject", feature = "NSManagedObjectID"))]
        #[method_id(@__retain_semantics Other existingObjectWithID:error:_)]
        pub unsafe fn existingObjectWithID_error(
            &self,
            object_id: &NSManagedObjectID,
        ) -> Result<Retained<NSManagedObject>, Retained<NSError>>;

        #[cfg(all(feature = "NSFetchRequest", feature = "NSPersistentStoreRequest"))]
        #[method_id(@__retain_semantics Other executeFetchRequest:error:_)]
        pub unsafe fn executeFetchRequest_error(
            &self,
            request: &NSFetchRequest,
        ) -> Result<Retained<NSArray>, Retained<NSError>>;

        #[cfg(all(
            feature = "NSPersistentStoreRequest",
            feature = "NSPersistentStoreResult"
        ))]
        #[method_id(@__retain_semantics Other executeRequest:error:_)]
        pub unsafe fn executeRequest_error(
            &self,
            request: &NSPersistentStoreRequest,
        ) -> Result<Retained<NSPersistentStoreResult>, Retained<NSError>>;

        #[cfg(feature = "NSManagedObject")]
        #[method(insertObject:)]
        pub unsafe fn insertObject(&self, object: &NSManagedObject);

        #[cfg(feature = "NSManagedObject")]
        #[method(deleteObject:)]
        pub unsafe fn deleteObject(&self, object: &NSManagedObject);

        #[cfg(feature = "NSManagedObject")]
        #[method(refreshObject:mergeChanges:)]
        pub unsafe fn refreshObject_mergeChanges(&self, object: &NSManagedObject, flag: bool);

        #[cfg(feature = "NSManagedObject")]
        #[method(detectConflictsForObject:)]
        pub unsafe fn detectConflictsForObject(&self, object: &NSManagedObject);

        #[method(observeValueForKeyPath:ofObject:change:context:)]
        pub unsafe fn observeValueForKeyPath_ofObject_change_context(
            &self,
            key_path: Option<&NSString>,
            object: Option<&AnyObject>,
            change: Option<&NSDictionary<NSString, AnyObject>>,
            context: *mut c_void,
        );

        #[method(processPendingChanges)]
        pub unsafe fn processPendingChanges(&self);

        #[cfg(feature = "NSPersistentStore")]
        #[method(assignObject:toPersistentStore:)]
        pub unsafe fn assignObject_toPersistentStore(
            &self,
            object: &AnyObject,
            store: &NSPersistentStore,
        );

        #[cfg(feature = "NSManagedObject")]
        #[method_id(@__retain_semantics Other insertedObjects)]
        pub unsafe fn insertedObjects(&self) -> Retained<NSSet<NSManagedObject>>;

        #[cfg(feature = "NSManagedObject")]
        #[method_id(@__retain_semantics Other updatedObjects)]
        pub unsafe fn updatedObjects(&self) -> Retained<NSSet<NSManagedObject>>;

        #[cfg(feature = "NSManagedObject")]
        #[method_id(@__retain_semantics Other deletedObjects)]
        pub unsafe fn deletedObjects(&self) -> Retained<NSSet<NSManagedObject>>;

        #[cfg(feature = "NSManagedObject")]
        #[method_id(@__retain_semantics Other registeredObjects)]
        pub unsafe fn registeredObjects(&self) -> Retained<NSSet<NSManagedObject>>;

        #[method(undo)]
        pub unsafe fn undo(&self);

        #[method(redo)]
        pub unsafe fn redo(&self);

        #[method(reset)]
        pub unsafe fn reset(&self);

        #[method(rollback)]
        pub unsafe fn rollback(&self);

        #[method(save:_)]
        pub unsafe fn save(&self) -> Result<(), Retained<NSError>>;

        #[method(refreshAllObjects)]
        pub unsafe fn refreshAllObjects(&self);

        #[deprecated = "Use a queue style context and -performBlockAndWait: instead"]
        #[method(lock)]
        pub unsafe fn lock(&self);

        #[deprecated = "Use a queue style context and -performBlockAndWait: instead"]
        #[method(unlock)]
        pub unsafe fn unlock(&self);

        #[deprecated = "Use a queue style context and -performBlock: instead"]
        #[method(tryLock)]
        pub unsafe fn tryLock(&self) -> bool;

        #[method(propagatesDeletesAtEndOfEvent)]
        pub unsafe fn propagatesDeletesAtEndOfEvent(&self) -> bool;

        #[method(setPropagatesDeletesAtEndOfEvent:)]
        pub unsafe fn setPropagatesDeletesAtEndOfEvent(
            &self,
            propagates_deletes_at_end_of_event: bool,
        );

        #[method(retainsRegisteredObjects)]
        pub unsafe fn retainsRegisteredObjects(&self) -> bool;

        #[method(setRetainsRegisteredObjects:)]
        pub unsafe fn setRetainsRegisteredObjects(&self, retains_registered_objects: bool);

        #[method(shouldDeleteInaccessibleFaults)]
        pub unsafe fn shouldDeleteInaccessibleFaults(&self) -> bool;

        #[method(setShouldDeleteInaccessibleFaults:)]
        pub unsafe fn setShouldDeleteInaccessibleFaults(
            &self,
            should_delete_inaccessible_faults: bool,
        );

        #[cfg(all(
            feature = "NSManagedObject",
            feature = "NSManagedObjectID",
            feature = "NSPropertyDescription"
        ))]
        #[method(shouldHandleInaccessibleFault:forObjectID:triggeredByProperty:)]
        pub unsafe fn shouldHandleInaccessibleFault_forObjectID_triggeredByProperty(
            &self,
            fault: &NSManagedObject,
            oid: &NSManagedObjectID,
            property: Option<&NSPropertyDescription>,
        ) -> bool;

        #[method(stalenessInterval)]
        pub unsafe fn stalenessInterval(&self) -> NSTimeInterval;

        #[method(setStalenessInterval:)]
        pub unsafe fn setStalenessInterval(&self, staleness_interval: NSTimeInterval);

        #[method_id(@__retain_semantics Other mergePolicy)]
        pub unsafe fn mergePolicy(&self) -> Retained<AnyObject>;

        #[method(setMergePolicy:)]
        pub unsafe fn setMergePolicy(&self, merge_policy: &AnyObject);

        #[cfg(feature = "NSManagedObject")]
        #[method(obtainPermanentIDsForObjects:error:_)]
        pub unsafe fn obtainPermanentIDsForObjects_error(
            &self,
            objects: &NSArray<NSManagedObject>,
        ) -> Result<(), Retained<NSError>>;

        #[method(mergeChangesFromContextDidSaveNotification:)]
        pub unsafe fn mergeChangesFromContextDidSaveNotification(
            &self,
            notification: &NSNotification,
        );

        #[method(mergeChangesFromRemoteContextSave:intoContexts:)]
        pub unsafe fn mergeChangesFromRemoteContextSave_intoContexts(
            change_notification_data: &NSDictionary,
            contexts: &NSArray<NSManagedObjectContext>,
        );

        #[cfg(feature = "NSQueryGenerationToken")]
        #[method_id(@__retain_semantics Other queryGenerationToken)]
        pub unsafe fn queryGenerationToken(&self) -> Option<Retained<NSQueryGenerationToken>>;

        #[cfg(feature = "NSQueryGenerationToken")]
        #[method(setQueryGenerationFromToken:error:_)]
        pub unsafe fn setQueryGenerationFromToken_error(
            &self,
            generation: Option<&NSQueryGenerationToken>,
        ) -> Result<(), Retained<NSError>>;

        #[method(automaticallyMergesChangesFromParent)]
        pub unsafe fn automaticallyMergesChangesFromParent(&self) -> bool;

        #[method(setAutomaticallyMergesChangesFromParent:)]
        pub unsafe fn setAutomaticallyMergesChangesFromParent(
            &self,
            automatically_merges_changes_from_parent: bool,
        );

        #[method_id(@__retain_semantics Other transactionAuthor)]
        pub unsafe fn transactionAuthor(&self) -> Option<Retained<NSString>>;

        #[method(setTransactionAuthor:)]
        pub unsafe fn setTransactionAuthor(&self, transaction_author: Option<&NSString>);
    }
);