Files
kotlin-fork/backend.native/tests/interop/objc/smoke.m
T
Svyatoslav Scherbina e8f97b0436 Represent Objective-C block pointers in methods as Kotlin functions
Also do some refactoring.
2017-10-17 13:23:21 +03:00

60 lines
1.1 KiB
Objective-C

#import <stdio.h>
#import <Foundation/NSString.h>
#import "smoke.h"
@interface CPrinter : NSObject <Printer>
-(void)print:(const char*)string;
@end;
@implementation CPrinter
-(void)print:(const char*)string {
printf("%s\n", string);
fflush(stdout);
}
@end;
@implementation Foo
@synthesize name;
-(instancetype)init {
if (self = [super init]) {
self.name = @"World";
}
return self;
}
-(void)helloWithPrinter:(id <Printer>)printer {
NSString* message = [NSString stringWithFormat:@"Hello, %@!", self.name];
[printer print:message.UTF8String];
}
-(void)dealloc {
printf("Deallocated\n");
}
@end;
@implementation Foo (FooExtensions)
-(void)hello {
CPrinter* printer = [[CPrinter alloc] init];
[self helloWithPrinter:printer];
}
@end;
void replacePairElements(id <MutablePair> pair, int first, int second) {
[pair update:0 add:(first - pair.first)];
[pair update:1 sub:(pair.second - second)];
}
int (^getSupplier(int x))(void) {
return ^{
return x;
};
}
Class (^ _Nonnull getClassGetter(NSObject* obj))() {
return ^{ return obj.class; };
}