This file contains hidden or 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 *networkSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
NetworkOperation *operation = [NetworkOperation getJSONOperationForURL:@"http://someurl"]; | |
[operation setCompletionBlockWithSuccess:^(NetworkOperation *theOperation, id *result) { | |
[subscriber sendNext:result]; | |
[subscriber sendCompleted]; | |
} failure:^(NetworkOperation *theOperation, NSError *error) { | |
[subscriber sendError:error]; | |
}]; |
This file contains hidden or 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
// | |
// TCAppDelegate.m | |
// Three Cents | |
// | |
// Created by Shaun Parker on 11/5/12. | |
// Copyright (c) 2012 Three Cents, Inc. All rights reserved. | |
// | |
#if DEBUG | |
//#import <SparkInspector/SparkInspector.h> |
This file contains hidden or 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) viewDidLoad { | |
//... | |
RACSignal *usernameIsValidSignal = RACObserve(self.viewModel, isUsernameValid); | |
RAC(self.goButton, enabled) = usernameIsValidSignal; | |
RAC(self.goButton, alpha) = [usernameIsValidSignal | |
map:^id(NSNumber *usernameIsValid) { | |
return usernameIsValid.boolValue ? @1.0 : @0.5; | |
}]; | |
} |
This file contains hidden or 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) viewDidLoad { | |
// ... | |
// create and get a reference to the signal | |
RACSignal *usernameValidSignal = RACObserve(self.viewModel, isUsernameValid); | |
// update the local property when this value changes | |
[usernameValidSignal subscribeNext:^(NSNumber *isValidNumber) { | |
self.usernameIsValid = isValidNumber.boolValue | |
}]; | |
} |
This file contains hidden or 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)textFieldDidChange:(UITextField *)sender { | |
// update the view-model | |
self.viewModel.username = sender.text; | |
// check if things are now valid | |
self.goButton.enabled = self.viewModel.isUsernameValid; | |
self.goButton.alpha = self.viewModel.isUsernameValid ? 1.0 : 0.5; | |
} |
This file contains hidden or 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) initWithViewModel:(MYTwitterLookupViewModel *) viewModel { | |
self = [super init]; | |
if (!self) return nil; | |
_viewModel = viewModel; | |
return self; | |
} | |
- (void) viewDidLoad { | |
[super viewDidLoad]; | |
_goButton.enabled = viewModel.isUsernameValid; | |
_goButton.alpha = viewModel.isUsernameValid ? 1 : 0.5; |
This file contains hidden or 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
self.keyboardObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillChangeFrameNotification object:nil queue:nil usingBlock:^(NSNotification *notification) { | |
@strongify(self); | |
NSDictionary *keyboardAnimationDetail = [notification userInfo]; | |
CGRect keyboardEndFrameWindow = [keyboardAnimationDetail[UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
double keyboardTransitionDuration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
UIViewAnimationCurve keyboardTransitionAnimationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue]; | |
This file contains hidden or 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
- (IBAction) didTapPrimaryUserAvatar | |
{ | |
MYTwitterUserProfileViewModel *userProfileViewModel = [self.viewModel viewModelForCurrentUser]; | |
MYTwitterUserProfileViewController *profileViewController = | |
[[MYTwitterUserProfileViewController alloc] initWithViewModel: userProfileViewModel]; | |
[self.navigationController pushViewController: profileViewController animated:YES]; | |
} |
This file contains hidden or 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
@interface MYTweetCellViewModel: NSObject | |
@property (nonatomic, strong, readonly) NSString *tweetAuthorFullName; | |
@property (nonatomic, strong, readonly) UIImage *tweetAuthorAvatarImage; | |
@property (nonatomic, strong, readonly) NSString *tweetContent; |
This file contains hidden or 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
@interface MYTwitterLookupViewModel: NSObject | |
@property (nonatomic, assign, readonly, getter=isUsernameValid) BOOL usernameValid; | |
@property (nonatomic, strong, readonly) NSString *userFullName; | |
@property (nonatomic, strong, readonly) UIImage *userAvatarImage; | |
@property (nonatomic, strong, readonly) NSArray *tweets; | |
@property (nonatomic, assign, readonly) BOOL allTweetsLoaded; | |
@property (nonatomic, strong, readwrite) NSString *username; |