Skip to content

Instantly share code, notes, and snippets.

@nverinaud
Last active December 29, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nverinaud/7695369 to your computer and use it in GitHub Desktop.
Save nverinaud/7695369 to your computer and use it in GitHub Desktop.
C# way of doing ObjC blocks.
/* Declaration */
// In ObjC
typedef void (^onCompletion)(bool completed);
// In C#
public delegate void OnCompletion(bool completed);
/* Implementation */
// In ObjC
- (void)myAsyncMethod:(onCompletion)completion
{
// blablabla...
completion(YES);
}
// In C#
public void MyAsyncMethod(OnCompletion completion)
{
// blablabla...
completion(true);
}
/* Usage */
// ObjC
[obj myAsyncMethod:^(completed) {
// finish !
}];
// C#
obj.MyAsyncMethod((completed) => {
// finish !
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment