mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-25 09:25:47 +00:00
35 lines
718 B
Objective-C
35 lines
718 B
Objective-C
#import <objc/runtime.h>
|
|
#import "PromiseKit/Promise.h"
|
|
#import "UIAlertView+PromiseKit.h"
|
|
|
|
|
|
@interface PMKAlertViewDelegater : NSObject <UIAlertViewDelegate> {
|
|
@public
|
|
void (^fulfiller)(id);
|
|
}
|
|
@end
|
|
|
|
|
|
@implementation PMKAlertViewDelegater
|
|
|
|
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
|
|
fulfiller(PMKManifold(@(buttonIndex), alertView));
|
|
PMKRelease(self);
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation UIAlertView (PromiseKit)
|
|
|
|
- (PMKPromise *)promise {
|
|
PMKAlertViewDelegater *d = [PMKAlertViewDelegater new];
|
|
PMKRetain(d);
|
|
self.delegate = d;
|
|
[self show];
|
|
return [PMKPromise new:^(id fulfiller, id rejecter){
|
|
d->fulfiller = fulfiller;
|
|
}];
|
|
}
|
|
|
|
@end
|