Represent Objective-C block pointers in methods as Kotlin functions
Also do some refactoring.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
caf6719fc4
commit
e8f97b0436
@@ -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 {
|
||||
|
||||
@@ -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; };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user