Create a gist now

Instantly share code, notes, and snippets.

#include <stdio.h>
int main() {
void (^hello)(void) = ^(void) {
printf("Hello, block!\n");
};
hello();
return 0;
}
#import <Foundation/NSObject.h>
@interface Fraction: NSObject {
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(int) numerator;
-(int) denominator;
@end
#import "Fraction.h"
#import <stdio.h>
@implementation Fraction
-(void) print {
printf( "%i/%i", numerator, denominator );
}
-(void) setNumerator: (int) n {
numerator = n;
}
-(void) setDenominator: (int) d {
denominator = d;
}
-(int) denominator {
return denominator;
}
-(int) numerator {
return numerator;
}
@end
#include <dispatch/dispatch.h>
#import <stdio.h>
#import "Fraction.h"
int main( int argc, const char *argv[] ) {
dispatch_queue_t queue = dispatch_queue_create(NULL, NULL);
Fraction *frac = [[Fraction alloc] init];
[frac setNumerator: 1];
[frac setDenominator: 3];
// print it
dispatch_sync(queue, ^{
printf( "The fraction is: " );
[frac print];
printf( "\n" );
});
dispatch_release(queue);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment