-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUUCoreData.h
98 lines (69 loc) · 4.03 KB
/
UUCoreData.h
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
//
// UUCoreData.h
// Useful Utilities - CoreData helpers
//
// License:
// You are free to use this code for whatever purposes you desire. The only requirement is that you smile everytime you use it.
//
// Contact: @cheesemaker or jon@threejacks.com
//
@import Foundation;
@import CoreData;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// UUCOreData
@interface UUCoreData : NSObject
// Setup the Core Data store. This MUST be called prior to using any other UUCoreData methods
+ (void) configureWithStoreUrl:(NSURL*)storeUrl modelDefinitionBundle:(NSBundle*)bundle;
// Delete's the store at the given URL and sets the shared persistentStoreCoordinator to nil. After this users
// MUST call configureWithStoreUrl again.
+ (NSError*) destroyStoreAtUrl:(NSURL*)storeUrl;
// Singleton managed object context shared by entire application
+ (NSManagedObjectContext*) mainThreadContext;
// Short lived managed object context for use on background threads
+ (NSManagedObjectContext*) workerThreadContext;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NSManagedObjectContext extensions
@interface NSManagedObjectContext (UUCoreData)
- (BOOL) uuSubmitChanges;
+ (id) uuConvertObject:(id)object toContext:(NSManagedObjectContext*)context;
- (void) uuDeleteObjects:(NSArray*)list;
- (void) uuDeleteAllObjects:(void(^)(void))completion;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NSManagedObject extensions
@interface NSManagedObject (UUCoreData)
+ (NSString*) uuEntityName;
+ (NSFetchRequest*) uuFetchRequestInContext:(NSManagedObjectContext*)context
predicate:(NSPredicate*)predicate
sortDescriptors:(NSArray*)sortDescriptors
limit:(NSNumber*)limit;
+ (NSFetchRequest*) uuFetchRequestInContext:(NSManagedObjectContext*)context
predicate:(NSPredicate*)predicate
sortDescriptors:(NSArray*)sortDescriptors
offset:(NSNumber*)offset
limit:(NSNumber*)limit;
+ (NSArray*) uuFetchObjectsWithPredicate:(NSPredicate*)predicate
context:(NSManagedObjectContext*)context;
+ (NSArray*) uuFetchObjectsWithPredicate:(NSPredicate*)predicate
sortDescriptors:(NSArray*)sortDescriptors
limit:(NSNumber*)limit
context:(NSManagedObjectContext*)context;
+ (NSArray*) uuFetchObjectsWithPredicate:(NSPredicate*)predicate
sortDescriptors:(NSArray*)sortDescriptors
offset:(NSNumber*)offset
limit:(NSNumber*)limit
context:(NSManagedObjectContext*)context;
+ (NSInteger) uuBatchUpdate:(NSDictionary*)properties predicate:(NSPredicate*)predicate context:(NSManagedObjectContext*)context;
+ (instancetype) uuFetchSingleObjectWithPredicate:(NSPredicate*)predicate
context:(NSManagedObjectContext*)context;
+ (instancetype) uuFetchSingleObjectWithPredicate:(NSPredicate*)predicate
sortDescriptors:(NSArray*)sortDescriptors
context:(NSManagedObjectContext*)context;
+ (instancetype) uuFetchOrCreateSingleEntityWithPredicate:(NSPredicate *)predicate
context:(NSManagedObjectContext *)context;
+ (void) uuDeleteObjectsWithPredicate:(NSPredicate*)predicate
context:(NSManagedObjectContext*)context;
+ (NSUInteger) uuCountObjectsWithPredicate:(NSPredicate*)predicate
context:(NSManagedObjectContext*)context;
@end