-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNFCoreDataExtensions.h
More file actions
103 lines (74 loc) · 5.42 KB
/
NFCoreDataExtensions.h
File metadata and controls
103 lines (74 loc) · 5.42 KB
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
//
// NFCoreDataExtensions.h
//
//
// Created by Nick Forge on 9/05/11.
// Copyright 2011 Nick Forge.
//
// This code is released under the MIT License.
//
#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
@interface NSManagedObjectContext (NFCoreDataExtensions)
// This is a wrapper around -executeFetchRequest:error:. If there's an error,
// the error description will be sent to NSLog.
- (NSArray *)executeFetchRequest:(NSFetchRequest *)request;
// This is a wrapper around -save:. If there's an error, the error description
// will be sent to NSLog.
- (BOOL)save;
//----------------------------------
//
// Creating NSFetchRequests
//
//----------------------------------
// No Predicate
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors;
// NSPredicate
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName withPredicate:(NSPredicate *)predicate;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicate:(NSPredicate *)predicate;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicate:(NSPredicate *)predicate;
// withPredicateFormat:
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName withPredicateFormat:(NSString *)predicateFormat, ...;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicateFormat:(NSString *)predicateFormat, ...;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicateFormat:(NSString *)predicateFormat, ...;
// withPredicateFormat: (va_list variant)
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName withPredicateFormat:(NSString *)predicateFormat arguments:(va_list)argList;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicateFormat:(NSString *)predicateFormat arguments:(va_list)argList;
- (NSFetchRequest *)fetchRequestForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicateFormat:(NSString *)predicateFormat arguments:(va_list)argList;
//----------------------------------
//
// Fetching Without an Explicit NSFetchRequest
//
//----------------------------------
// Multi-object Fetches
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName withPredicate:(NSPredicate *)predicate;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicate:(NSPredicate *)predicate;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicate:(NSPredicate *)predicate;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName withPredicateFormat:(NSString *)predicateFormat, ...;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicateFormat:(NSString *)predicateFormat, ...;
- (NSArray *)fetchObjectsForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicateFormat:(NSString *)predicateFormat, ...;
// Single-object Fetches
- (id)fetchFirstObjectForEntityName:(NSString *)entityName;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName withPredicate:(NSPredicate *)predicate;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicate:(NSPredicate *)predicate;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicate:(NSPredicate *)predicate;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName withPredicateFormat:(NSString *)predicateFormat, ...;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName sortByKey:(NSString *)key ascending:(BOOL)ascending withPredicateFormat:(NSString *)predicateFormat, ...;
- (id)fetchFirstObjectForEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors withPredicateFormat:(NSString *)predicateFormat, ...;
@end
@interface NSFetchRequest (NFCoreDataExtensions)
+ (NSFetchRequest *)fetchRequestWithEntityName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context;
@end
@interface NSFetchedResultsController (NFCoreDataExtensions)
+ (NSFetchedResultsController *)fetchedResultsControllerWithFetchRequest:(NSFetchRequest *)fetchRequest managedObjectContext:(NSManagedObjectContext *)context sectionNameKeyPath:(NSString *)keyPath cacheName:(NSString *)cacheName;
// This is a wrapper around -performFetch:.If there's an error,
// the error description will be sent to NSLog.
- (BOOL)performFetch;
@end