-
-
Save beelsebob/1319587 to your computer and use it in GitHub Desktop.
Fire an NSTimer using a block as execution code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSAlertWithBlocks.h | |
| // | |
| // Created by Thomas Davie on 26/12/2009. | |
| // Copyright 2009 Thomas Davie. All rights reserved. | |
| // | |
| #import <Cocoa/Cocoa.h> | |
| @interface NSAlert (WithBlocks) | |
| - (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void(^)(NSInteger result))completionHandler; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSAlertWithBlocks.m | |
| // | |
| // Created by Thomas Davie on 26/12/2009. | |
| // Copyright 2009 Thomas Davie. All rights reserved. | |
| // | |
| #import "NSAlertWithBlocks.h" | |
| @interface NSAlert (WithBlocksPrivate) | |
| - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo; | |
| @end | |
| @implementation NSAlert (WithBlocks) | |
| - (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void(^)(NSInteger result))completionHandler | |
| { | |
| [self beginSheetModalForWindow:window modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:[completionHandler copy]]; | |
| } | |
| - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo | |
| { | |
| void(^handler)(NSInteger result) = (void(^)(NSInteger result))contextInfo; | |
| handler(returnCode); | |
| [handler release]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment