Skip to content

Instantly share code, notes, and snippets.

View jdewind's full-sized avatar

Justin DeWind jdewind

  • LifeWorks
  • Grand Rapids
View GitHub Profile
@interface ApplicationDelegate<UIApplicationDelegate>
@end
@implementation ApplicationDelegate
- (RACSignal *)rac_registeredForRemoteNotifications {
RACSignal *signal = objc_getAssociatedObject(self, _cmd);
if (signal != nil) return signal;
RACSignal *didRegisterForRemoteNotification = [[self rac_signalForSelector: @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:) fromProtocol: @protocol(UIApplicationDelegate)] map: ^(RACTuple *tuple) {
return tuple.second;
@jdewind
jdewind / subform_tap.rb
Created May 27, 2014 18:54
Subform ontap
@form.row(:subform_key).row(:a_row).on_tap |do|
end
- (void) load {
RACSignal *signal = [[api fetchPerson: personId] flattenMap: ^(id person) {
return [[[api fetchFamilyMembers: person.id] map: ^(id familyMembers) {
return [self buildViewModel: person familyMembers: familyMembers];
}] startWith: [self buildViewModel: person familyMembers: @[]];
}];
}
- (void) load {
RACSignal* signal = [api fetchPerson: personId];
[signal subscribeNext: ^(id person) {
[view renderPerson: person];
}];
[signal subscribeError: ^(NSError *error) {
[view renderError];
}];
}
- (instancetype)fetchPerson:(NSInteger)personId {
[[self fetchAtEndPoint: [NSString stringWithFormat: @"/person/%d", personId], mapTo: [Person class]] flattenMap: ^(id person) {
if(!person) {
return [RACSignal error: nil];
} else {
return [RACSignal return: person];
}
}];
}
class Car
include RequireOptions
def go(opts)
gear, speed = require_options(opts, :speed, :gear)
# ...
end
end
@implementation ConfirmationAlert
+ (void)show:(NSString *)message delegate:(id<UIAlertViewDelegate>)theDelegate {
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Confirm" message:message delegate:theDelegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil] autorelease];
[alertView show];
}
@end
+ (void)showOneConfirmationAlert:(NSMutableDictionary *)externalState {
[BlockConfirmationAlert show:@"Are you sure about this?"
confirmed:^(UIAlertView *alertView) {
//...
NSLog([externalState objectForKey:@"Key"]);
}
canceled:^(UIAlertView *alertView) {
//...
NSLog([externalState objectForKey:@"DifferentKey"]);
}];
@implementation MyObject
-(void)showOneConfirmationAlert:(NSMutableDictionary *)externalState {
externalStateForOneConfirmationAlert = [externalState retain];
oneConfirmationAlert = [[ConfirmationAlert show:@"Are you sure about this?" delegate:self] retain];
}
-(void)showAnotherConfirmationAlert:(NSMutableDictionary *)externalState {
externalStateForAnotherConfirmationAlert = [externalState retain];
oneConfirmationAlert = [[ConfirmationAlert show:@"Again, are you sure?" delegate:self] retain];
}
typedef void (^ConfirmationBlock)(UIAlertView *);