Files
swift-mirror/test/Casting/Inputs/Cast_Blocks/Cast_Blocks.m
Tim Kientzle c262248a27 [ObjC Bridging] Consistently bridge block types verbatim
A `@convention(block)` closure in Swift is completely compatible with Objective-C
and does not need to be wrapped in a `__SwiftValue` box for use.

Previously, it was bridged verbatim when appearing by itself, but
could end up boxed when it went through array bridging.

The test verifies that:
* Objective-C does not see a `__SwiftValue` box
* Swift `type(of:)` does not see a `__SwiftValue` box
* Objective-C can actually call the closure

Resolves rdar://138132321
2024-11-08 13:49:21 -08:00

20 lines
399 B
Objective-C

#import <objc/runtime.h>
#import "Cast_Blocks.h"
BOOL ObjCThinksObjectIsSwiftValue(id obj) {
Class cls = object_getClass(obj);
const char *name = class_getName(cls);
if (strcmp(name, "__SwiftValue") == 0) {
return TRUE;
} else {
return FALSE;
}
}
void ObjCCanCallBlock(id block_as_id) {
typedef void(^blockType)(void);
blockType block = (blockType)block_as_id;
block();
}