Skip to content

Commit

Permalink
Added RGAlertViewDelegate class.
Browse files Browse the repository at this point in the history
  • Loading branch information
rokgregoric committed Mar 5, 2014
1 parent 161308a commit a9dcb87
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CoreData/RGCoreDataManagedDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ - (id)init {

// Set our document up for automatic migrations
self.document.persistentStoreOptions = @{
NSMigratePersistentStoresAutomaticallyOption: @YES,
NSInferMappingModelAutomaticallyOption: @YES,
};
}
NSMigratePersistentStoresAutomaticallyOption: @YES,
NSInferMappingModelAutomaticallyOption: @YES,
};
}
return self;
}

Expand Down
38 changes: 38 additions & 0 deletions RGAlertViewDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// RGAlertViewDelegate.h
//
// Created by Rok Gregorič on 27. 02. 14.
// Copyright (c) 2014 Rok Gregorič. All rights reserved.
//

// USAGE:
//
// __weak UIViewController *wself = self;
// self.alertViewDelegate = [RGAlertViewDelegate delegateWithHandler:^(NSInteger clickedButtonIndex) {
// switch (clickedButtonIndex) {
// case 0: { // No
// [wself noTapped];
// } break;
// case 1: { // Yes
// [wself yesTapped];
// } break;
// }
// wself.alertViewDelegate = nil;
// }];
//
// UIAlertView *alert = [UIAlertView.alloc initWithTitle:@"Question" message:@"Are you sure?" delegate:self.alertViewDelegate cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
// [alert show];

#import <UIKit/UIKit.h>

typedef void (^DelegateHandler)(NSInteger clickedButtonIndex);

@interface RGAlertViewDelegate : NSObject <UIAlertViewDelegate>

@property (nonatomic, copy) DelegateHandler delegateHandler;

+ (instancetype)delegateWithHandler:(DelegateHandler)delegateHandler;

@end


24 changes: 24 additions & 0 deletions RGAlertViewDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// RGAlertViewDelegate.m
//
// Created by Rok Gregorič on 27. 02. 14.
// Copyright (c) 2014 Rok Gregorič. All rights reserved.
//

#import "RGAlertViewDelegate.h"

@implementation RGAlertViewDelegate

+ (instancetype)delegateWithHandler:(DelegateHandler)delegateHandler {
RGAlertViewDelegate *alertViewDelegate = RGAlertViewDelegate.new;
alertViewDelegate.delegateHandler = delegateHandler;
return alertViewDelegate;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (self.delegateHandler) {
self.delegateHandler(buttonIndex);
}
}

@end

0 comments on commit a9dcb87

Please sign in to comment.