Represent Objective-C block pointers in methods as Kotlin functions

Also do some refactoring.
This commit is contained in:
Svyatoslav Scherbina
2017-10-16 17:22:26 +03:00
committed by SvyatoslavScherbina
parent caf6719fc4
commit e8f97b0436
18 changed files with 412 additions and 80 deletions
+11
View File
@@ -25,3 +25,14 @@
@end;
void replacePairElements(id <MutablePair> pair, int first, int second);
int invoke1(int arg, int (^block)(int)) {
return block(arg);
}
void invoke2(void (^block)(void)) {
block();
}
int (^getSupplier(int x))(void);
Class (^ _Nonnull getClassGetter(NSObject* obj))(void);
@@ -8,7 +8,17 @@ fun main(args: Array<String>) {
}
fun run() {
println(
getSupplier(
invoke1(42) { it * 2 }
)!!()
)
val foo = Foo()
val classGetter = getClassGetter(foo)
invoke2 { println(classGetter()) }
foo.hello()
foo.name = "everybody"
foo.helloWithPrinter(object : NSObject(), PrinterProtocol {
+10
View File
@@ -47,3 +47,13 @@ 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; };
}