Created
September 24, 2012 11:35
-
-
Save eternalstorms/3775556 to your computer and use it in GitHub Desktop.
Pass a block as a void pointer in ARC
This file contains 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
- (void)delete | |
{ | |
void (^myBlock)() = ^{/*some block action*/}; | |
NSBeginCriticalAlertSheet(NSLocalizedString(@"ReallyDeleteWarning", nil), | |
NSLocalizedString(@"Delete", nil), | |
NSLocalizedString(@"Cancel", nil), nil, self.window, self, nil, | |
@selector(deleteAlertWindow:didDismissWithCode:context:), | |
(__bridge_retained void *)([myBlock copy]), | |
NSLocalizedString(@"ReallyDeleteWarningMsg", nil)); | |
} | |
- (void)deleteAlertWindow:(NSWindow *)sheet didDismissWithCode:(NSInteger)code context:(void *)ctx//(void (^)(void))block | |
{ | |
void (^myBlock)() = (__bridge_transfer typeof(myBlock))ctx; | |
if (code == NSAlertDefaultReturn) | |
{ | |
if (myBlock != nil) | |
myBlock(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment