Skip to content

Optimisations for swift #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ReactiveCoreData/NSManagedObject+ReactiveCoreData.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ + (RACSignal *)findOne;

+ (NSString *)entityName;
{
return NSStringFromClass(self);
return [[NSStringFromClass(self) componentsSeparatedByString:@"."] lastObject];
}

+ (instancetype)insert;
Expand Down
10 changes: 5 additions & 5 deletions ReactiveCoreData/RACSignal+ReactiveCoreData.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
- (RACSignal *)count;

// Modifies NSFetchRequest to set predicate
- (RACSignal *)where:(id)predicateOrSignal;

- (RACSignal *)whereObjectMatches:(id)predicateOrSignal;
// Returns a signal with NSFetchRequest's predicate modified according to format and its arguments
//
// The format is passed to NSPredicate as is
// The arguments can be either signals or objects that can be returned in signals
// Any new value in any of the argument signals will result in update of the fetch request
// and possible execution of the request, if there's a `fetch` later.
// This brings the predicates into the reactive world
- (RACSignal *)where:(NSString *)format args:(NSArray *)args;
- (RACSignal *)whereObjectMatches:(NSString *)format args:(NSArray *)args;

// A convenience method for a common predicate case
//
// Create a "%K == %@" predicate with key and value as arguments
- (RACSignal *)where:(id)key equals:(id)value;
- (RACSignal *)whereObjectMatches:(id)key equals:(id)value;

// A convenience method for a common predicate case
//
Expand All @@ -50,7 +50,7 @@
// This is useful when the using it to filter text from the search field, which can be empty
// `options` parameter is an optional string like `@"cd"` that can be added after CONTAINS inside brackets.
// For example, passing @"cd" for `options` will result in a CONTAINS[cd] predicate
- (RACSignal *)where:(id)key contains:(id)valueOrSignal options:(NSString *)optionsOrNil;
- (RACSignal *)whereObjectMatches:(id)key contains:(id)valueOrSignal options:(NSString *)optionsOrNil;

// Modifies the NSFetchRequest to set passed-in limit
- (RACSignal *)limit:(id)limitOrSignal;
Expand Down
14 changes: 7 additions & 7 deletions ReactiveCoreData/RACSignal+ReactiveCoreData.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ - (RACSignal *)fetchInMOC:(NSManagedObjectContext *)moc;
return [[moc executeRequest:req] map:^id(id value) {
return [value lastObject];
}];
}
}
else {
return [moc executeRequest:req];
}
Expand Down Expand Up @@ -46,7 +46,7 @@ - (RACSignal *)count;

#pragma mark - Operations modifying NSFetchRequest

- (RACSignal *)where:(id)predicateOrSignal;
- (RACSignal *)whereObjectMatches:(id)predicateOrSignal;
{
RACSignal *predicateSignal = [self rcd_convertToSignal:predicateOrSignal];
return [[[self combineLatestWith:predicateSignal]
Expand All @@ -56,12 +56,12 @@ - (RACSignal *)where:(id)predicateOrSignal;
}] setNameWithFormat:@"[%@] -where:%@", self.name, predicateOrSignal];
}

- (RACSignal *)where:(id)key equals:(id)value;
- (RACSignal *)whereObjectMatches:(id)key equals:(id)value;
{
return [self where:@"%K == %@" args:@[key, value]];
return [self whereObjectMatches:@"%K == %@" args:@[key, value]];
}

- (RACSignal *)where:(NSString *)format args:(NSArray *)args;
- (RACSignal *)whereObjectMatches:(NSString *)format args:(NSArray *)args;
{
NSArray *signals = [self rcd_convertToSignals:args];
return [[[self combineLatestWith:[RACSignal combineLatest:signals]]
Expand All @@ -72,7 +72,7 @@ - (RACSignal *)where:(NSString *)format args:(NSArray *)args;
}] setNameWithFormat:@"[%@] -where:%@ args:%@", self.name, format, args];
}

- (RACSignal *)where:(id)key contains:(id)valueOrSignal options:(NSString *)optionsOrNil;
- (RACSignal *)whereObjectMatches:(id)key contains:(id)valueOrSignal options:(NSString *)optionsOrNil;
{
NSParameterAssert(valueOrSignal);
NSParameterAssert(key);
Expand All @@ -86,7 +86,7 @@ - (RACSignal *)where:(id)key contains:(id)valueOrSignal options:(NSString *)opti
else {
whereClause = @"%K CONTAINS %@";
}
return [self where:whereClause args:@[key, filter]];
return [self whereObjectMatches:whereClause args:@[key, filter]];
}
else
return self;
Expand Down