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
- (void)shiftKeyboardIfNecessary { | |
CGRect viewFrame = self.view.frame; | |
CGRect activeTextFieldFrame = self.activeTextField.frame; | |
CGFloat bottomPadding = 4; | |
// The lowest point visible on the screen is the height of the screen minus the height of the keyboard, then adjusted by the current position | |
// of the view. So, if the view has already been shifted upwards (negative origin), then more of the lower part of the screen is visible. | |
CGFloat lowestPointCoveredByKeyboard = -viewFrame.origin.y + viewFrame.size.height - self.keyboardFrame.size.height; | |
// The active text field's lowest point is its origin.y + its height (so, if it was at y=200, and is 21px tall, then the lowest point is 221. |
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
- (RACSignal *)fetchJSONFromURL:(NSURL *)url { | |
NSParameterAssert(url); | |
return [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
NSURLSession * session = [NSURLSession sharedSession]; | |
NSURLSessionDataTask * dataTask = [session dataTaskWithURL:url completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) { | |
if (data) { |
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
#import "NSManagedObject+MVVM.h" | |
#import <RBCoreDataStack/NSManagedObject+RBCoreDataStack.h> | |
@implementation NSManagedObject (MVVM) | |
+ (RACSignal *)fetchAllSignalInContext:(NSManagedObjectContext *)context { | |
return [self fetchAllSignalWithPredicate:nil inContext:context]; | |
} | |
+ (RACSignal *)fetchAllSignalWithPredicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context { |
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
@import Foundation; | |
@import UIKit; | |
typedef UITableViewCell *(^MVVMCellCreatorBlock)(UITableView * tableView, NSIndexPath * indexPath, id object); | |
@interface MVVMTableViewListDataSource : NSObject <UITableViewDataSource> | |
- (id)initWithObjects:(NSArray *)objects cellCreator:(MVVMCellCreatorBlock)block; |
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
// show a network activity indicator when the search is being executed | |
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = | |
self.viewModel.searchCommand.executing; |
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
/////// | |
//signal | |
/////// | |
//conventional | |
- (BOOL)isFormValid { | |
return [self.usernameField.text length] > 0 && | |
[self.emailField.text length] > 0 && | |
[self.passwordField.text length] > 0 && | |
[self.passwordField.text isEqual:self.passwordVerificationField.text]; |
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
// creates a signal that fetches an image in the background, delivering | |
// it on the UI thread. This signal 'cancels' itself if the cell is re-used before the | |
// image is downloaded. | |
-(RACSignal *)signalForImage:(NSURL *)imageUrl { | |
RACScheduler *scheduler = [RACScheduler schedulerWithPriority:RACSchedulerPriorityBackground]; | |
RACSignal *imageDownloadSignal = [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
NSData *data = [NSData dataWithContentsOfURL:imageUrl]; | |
UIImage *image = [UIImage imageWithData:data]; |
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
- (id)init { | |
if (self = [super init]) { | |
[self initialize]; | |
} | |
return self; | |
} | |
- (void) initialize { | |
// set up access to twitter |
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
RAC(self, timestamp) = [[RACObserve(self, model.timestamp) map:^id(NSDate *value) { | |
return [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
NSUInteger days, hours, minutes, seconds; | |
absoluteTimeUnitsSinceDate(value, &days, &hours, &minutes, &seconds); | |
NSUInteger updateAfter = NSNotFound; | |
NSString *currentValue = nil; | |
if (days) { | |
currentValue = [NSString stringWithFormat:@"%ud", (unsigned int)days]; | |
} | |
else if (hours) { |
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
//the trick is to use replayLast or replayLazily signal operation, which basically creates buffer and hold in it cached value! | |
- (void)getData:(id)inputParam forKey:(NSString *)key withCompletionBlock:(void (^)(id data, NSError *error)) { | |
if (!_cache[key]) { | |
RACSignal *dataSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
id operation = _actualGetDataRequest(inputParam, ^(id data, NSError *error) { | |
if (error) { | |
[subscriber sendError:error]; | |
} |
OlderNewer