forked from shaojiankui/JKCategories
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NSDecimalNumber+Extensions NSNotificationCenter UIView+Shake UINavigationItem+Loading
- Loading branch information
Jakey
authored and
Jakey
committed
Jun 5, 2015
1 parent
3c42045
commit 7c48078
Showing
41 changed files
with
1,627 additions
and
51 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Categories/CoreData/NSFetchRequest/NSFetchRequest+Extensions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// NSFetchRequest+Extensions.h | ||
// | ||
// Created by Wess Cope on 9/23/11. | ||
// Copyright 2012. All rights reserved. | ||
// | ||
|
||
#import <CoreData/CoreData.h> | ||
|
||
typedef void (^FetchObjectsCallback)(NSArray *fetchedObjects, NSError *error); | ||
typedef void (^FetchObjectCallback)(id fetchedObject, NSError * error); | ||
|
||
@interface NSFetchRequest(Extensions) | ||
|
||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity; | ||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity predicate:(NSPredicate *)predicate; | ||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity sortDescriptors:(NSArray *)sortDescriptors; | ||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors; | ||
|
||
- (id)initWithEntity:(NSEntityDescription *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors; | ||
|
||
@end |
44 changes: 44 additions & 0 deletions
44
Categories/CoreData/NSFetchRequest/NSFetchRequest+Extensions.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// NSFetchRequest+Extensions.m | ||
// | ||
// Created by Wess Cope on 9/23/11. | ||
// Copyright 2012. All rights reserved. | ||
// | ||
|
||
#import "NSFetchRequest+Extensions.h" | ||
|
||
@implementation NSFetchRequest(Extensions) | ||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity | ||
{ | ||
return [[self alloc] initWithEntity:entity predicate:nil sortDescriptors:nil]; | ||
} | ||
|
||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity predicate:(NSPredicate *)predicate | ||
{ | ||
return [[self alloc] initWithEntity:entity predicate:predicate sortDescriptors:nil]; | ||
} | ||
|
||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity sortDescriptors:(NSArray *)sortDescriptors | ||
{ | ||
return [[self alloc] initWithEntity:entity predicate:nil sortDescriptors:sortDescriptors]; | ||
} | ||
|
||
+ (id)fetchRequestWithEntity:(NSEntityDescription *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors | ||
{ | ||
return [[self alloc] initWithEntity:entity predicate:predicate sortDescriptors:sortDescriptors]; | ||
} | ||
|
||
- (id)initWithEntity:(NSEntityDescription *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors | ||
{ | ||
self = [self init]; | ||
if(self) | ||
{ | ||
self.entity = entity; | ||
self.predicate = predicate; | ||
self.sortDescriptors = sortDescriptors; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
@end |
24 changes: 24 additions & 0 deletions
24
Categories/CoreData/NSManagedObject/NSManagedObject+Extensions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// NSManagedObject+Extensions.h | ||
// kemmler | ||
// | ||
// Created by Lars Kuhnt on 28.10.13. | ||
// Copyright (c) 2013 Coeus Solutions GmbH. All rights reserved. | ||
// | ||
|
||
#import <CoreData/CoreData.h> | ||
#import "NSManagedObjectContext+Extensions.h" | ||
|
||
@interface NSManagedObject (Extensions) | ||
|
||
+ (id)create:(NSManagedObjectContext*)context; | ||
+ (id)create:(NSDictionary*)dict inContext:(NSManagedObjectContext*)context; | ||
+ (id)find:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context; | ||
+ (id)find:(NSPredicate *)predicate sortDescriptors:(NSArray*)sortDescriptors inContext:(NSManagedObjectContext *)context; | ||
+ (NSArray*)all:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context; | ||
+ (NSArray*)all:(NSPredicate *)predicate sortDescriptors:(NSArray*)sortDescriptors inContext:(NSManagedObjectContext *)context; | ||
+ (NSUInteger)count:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)contex; | ||
+ (NSString *)entityName; | ||
+ (NSError*)deleteAll:(NSManagedObjectContext*)context; | ||
|
||
@end |
70 changes: 70 additions & 0 deletions
70
Categories/CoreData/NSManagedObject/NSManagedObject+Extensions.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// NSManagedObject+Extensions.m | ||
// kemmler | ||
// | ||
// Created by Lars Kuhnt on 28.10.13. | ||
// Copyright (c) 2013 Coeus Solutions GmbH. All rights reserved. | ||
// | ||
|
||
#import "NSManagedObject+Extensions.h" | ||
|
||
@implementation NSManagedObject (Extensions) | ||
|
||
+ (id)create:(NSManagedObjectContext*)context { | ||
return [NSEntityDescription insertNewObjectForEntityForName:[self entityName] inManagedObjectContext:context]; | ||
} | ||
|
||
+ (id)create:(NSDictionary*)dict inContext:(NSManagedObjectContext*)context { | ||
id instance = [self create:context]; | ||
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | ||
[instance setValue:obj forKey:key]; | ||
}]; | ||
return instance; | ||
} | ||
|
||
+ (id)find:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context { | ||
return [context fetchObjectForEntity:[self entityName] predicate:predicate]; | ||
} | ||
|
||
+ (id)find:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors inContext:(NSManagedObjectContext *)context { | ||
return [context fetchObjectForEntity:[self entityName] predicate:predicate sortDescriptors:sortDescriptors]; | ||
} | ||
|
||
+ (NSArray*)all:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context { | ||
return [context fetchObjectsForEntity:[self entityName] predicate:predicate]; | ||
} | ||
|
||
+ (NSArray *)all:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors inContext:(NSManagedObjectContext *)context { | ||
return [context fetchObjectsForEntity:[self entityName] predicate:predicate sortDescriptors:sortDescriptors]; | ||
} | ||
|
||
+ (NSUInteger)count:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context { | ||
NSFetchRequest *request = [[NSFetchRequest alloc] init]; | ||
NSEntityDescription *entity = [NSEntityDescription entityForName:[self entityName] inManagedObjectContext:context]; | ||
[request setPredicate:predicate]; | ||
[request setEntity:entity]; | ||
NSError *error = nil; | ||
return [context countForFetchRequest:request error:&error]; | ||
} | ||
|
||
+ (NSString *)entityName { | ||
return [NSString stringWithCString:object_getClassName(self) encoding:NSASCIIStringEncoding]; | ||
} | ||
|
||
+ (NSError*)deleteAll:(NSManagedObjectContext*)context { | ||
NSFetchRequest * req = [[NSFetchRequest alloc] init]; | ||
[req setEntity:[NSEntityDescription entityForName:[self entityName] inManagedObjectContext:context]]; | ||
[req setIncludesPropertyValues:NO]; //only fetch the managedObjectID | ||
|
||
NSError * error = nil; | ||
NSArray * objects = [context executeFetchRequest:req error:&error]; | ||
//error handling goes here | ||
for (NSManagedObject * obj in objects) { | ||
[context deleteObject:obj]; | ||
} | ||
NSError *saveError = nil; | ||
[context save:&saveError]; | ||
return error; | ||
} | ||
|
||
@end |
49 changes: 49 additions & 0 deletions
49
Categories/CoreData/NSManagedObjectContext/NSManagedObjectContext+Extensions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// NSManagedObjectContext+Extensions.h | ||
// | ||
// Created by Wess Cope on 9/23/11. | ||
// Copyright 2012. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <CoreData/CoreData.h> | ||
#import "NSFetchRequest+Extensions.h" | ||
|
||
typedef void (^ContextCallback)(NSManagedObjectContext *context); | ||
typedef void (^ContextObjectCallback)(NSManagedObjectContext *context, id object); | ||
typedef void (^ContextObjectsCallback)(NSManagedObjectContext *context, NSArray *objects); | ||
|
||
|
||
@interface NSManagedObjectContext(Extensions) | ||
|
||
#pragma mark - Conveince Property | ||
@property (nonatomic, readonly) NSManagedObjectModel *objectModel; | ||
|
||
#pragma mark - Sync methods | ||
- (NSArray *)fetchObjectsForEntity:(NSString *)entity; | ||
- (NSArray *)fetchObjectsForEntity:(NSString *)entity predicate:(NSPredicate *)predicate; | ||
- (NSArray *)fetchObjectsForEntity:(NSString *)entity sortDescriptors:(NSArray *)sortDescriptors; | ||
- (NSArray *)fetchObjectsForEntity:(NSString *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors; | ||
- (NSArray *)fetchObjectsForEntity:(NSString *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors fetchLimit:(NSUInteger)limit; | ||
- (id)fetchObjectForEntity:(NSString *)entity; | ||
- (id)fetchObjectForEntity:(NSString *)entity predicate:(NSPredicate *)predicate; | ||
- (id)fetchObjectForEntity:(NSString *)entity sortDescriptors:(NSArray *)sortDescriptors; | ||
- (id)fetchObjectForEntity:(NSString *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors; | ||
|
||
#pragma mark - Async Methods | ||
- (void)fetchObjectsForEntity:(NSString *)entity callback:(FetchObjectsCallback)callback; | ||
- (void)fetchObjectsForEntity:(NSString *)entity predicate:(NSPredicate *)predicate callback:(FetchObjectsCallback)callback; | ||
- (void)fetchObjectsForEntity:(NSString *)entity sortDescriptors:(NSArray *)sortDescriptors callback:(FetchObjectsCallback)callback; | ||
- (void)fetchObjectsForEntity:(NSString *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors callback:(FetchObjectsCallback)callback; | ||
|
||
- (void)fetchObjectForEntity:(NSString *)entity callback:(FetchObjectCallback)callback; | ||
- (void)fetchObjectForEntity:(NSString *)entity predicate:(NSPredicate *)predicate callback:(FetchObjectCallback)callback; | ||
- (void)fetchObjectForEntity:(NSString *)entity sortDescriptors:(NSArray *)sortDescriptors callback:(FetchObjectCallback)callback; | ||
- (void)fetchObjectForEntity:(NSString *)entity predicate:(NSPredicate *)predicate sortDescriptors:(NSArray *)sortDescriptors callback:(FetchObjectCallback)callback; | ||
|
||
- (void)fetchRequest:(NSFetchRequest *)fetchRequest withCallback:(FetchObjectsCallback)callback; | ||
|
||
#pragma mark - Insert New Entity | ||
- (id)insertEntity:(NSString *)entity; | ||
- (void)deleteEntity:(NSString *)entity withPredicate:(NSPredicate *)predicate; | ||
@end |
Oops, something went wrong.