Skip to content

Instantly share code, notes, and snippets.

View bobspryn's full-sized avatar
🌴
On vacation

Bob Spryn bobspryn

🌴
On vacation
View GitHub Profile
//
// 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>
- (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;
}];
}
@bobspryn
bobspryn / basicSubscribe.m
Last active August 29, 2015 14:08
basicSubscribe.m
- (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
}];
}
- (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;
}
- (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;
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];
- (IBAction) didTapPrimaryUserAvatar
{
MYTwitterUserProfileViewModel *userProfileViewModel = [self.viewModel viewModelForCurrentUser];
MYTwitterUserProfileViewController *profileViewController =
[[MYTwitterUserProfileViewController alloc] initWithViewModel: userProfileViewModel];
[self.navigationController pushViewController: profileViewController animated:YES];
}
@interface MYTweetCellViewModel: NSObject
@property (nonatomic, strong, readonly) NSString *tweetAuthorFullName;
@property (nonatomic, strong, readonly) UIImage *tweetAuthorAvatarImage;
@property (nonatomic, strong, readonly) NSString *tweetContent;
@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;
- (void) viewDidLoad {
[super viewDidLoad];
self.fetchUserMenuDataCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [TCAPI fetchUserMenuData];
}];
RAC(self, menuData) = [self.fetchUserMenuDataCommand.executionSignals switchToLatest];
RACSignal *userIsLoggedInSignal = [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:kUserLoggedOutNotification object:nil]