mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-26 09:35:47 +00:00
35 lines
772 B
Objective-C
35 lines
772 B
Objective-C
#import <objc/runtime.h>
|
|
#import "PromiseKit/Promise.h"
|
|
#import "UIActionSheet+PromiseKit.h"
|
|
|
|
|
|
@interface PMKActionSheetDelegater : NSObject <UIActionSheetDelegate> {
|
|
@public
|
|
void (^fulfiller)(id);
|
|
}
|
|
@end
|
|
|
|
|
|
@implementation PMKActionSheetDelegater
|
|
|
|
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
|
|
fulfiller(PMKManifold(@(buttonIndex), actionSheet));
|
|
PMKRelease(self);
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation UIActionSheet (PromiseKit)
|
|
|
|
- (PMKPromise *)promiseInView:(UIView *)view {
|
|
PMKActionSheetDelegater *d = [PMKActionSheetDelegater new];
|
|
PMKRetain(d);
|
|
self.delegate = d;
|
|
[self showInView:view];
|
|
return [PMKPromise new:^(id fulfiller, id rejecter){
|
|
d->fulfiller = fulfiller;
|
|
}];
|
|
}
|
|
|
|
@end
|