As of Swift 5.10 (Xcode 15.3), if I have this UIButton subclass in Swift:
@objc class TestButton : UIButton {
@objc var textColorResolver: ((UIControl.State) -> UIColor?)?
}
And I refer to it from an Objective-C file marked as Objective-C++:
TestButton *btn = [[TestButton alloc] init];
btn.textColorResolver = ^UIColor * _Nullable(UIControlState state) {
return [UIColor redColor];
};
I get this error:
Incompatible block pointer types assigning to 'UIColor * _Nullable (^ _Nullable)(int)' from 'UIColor * _Nullable (^)(UIControlState)'
It looks like UIControlState is being typed as a raw int by the C++ conversion? How do I resolve this?
FWIW, I also get an error Unknown type name 'State' in the generated Swift header file for this button class:
SWIFT_CLASS("_TtC16ConcurencyTester10TestButton")
@interface TestButton : UIButton
@property (nonatomic, copy) UIColor * _Nullable (^ _Nullable textColorResolver)(State);
- (nonnull instancetype)initWithFrame:(CGRect)frame OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)coder OBJC_DESIGNATED_INITIALIZER;
@end
pookjw
(Jinwoo Kim)
2
It seems that C++ interop does not yet support exposing to C++ such as NS_SWIFT_NAME(UIAccessibility.DirectTouchOptions) (defined in UIAccessibilityConstants.h), or SwiftName: UIControl.State (defined in UIKit.apinotes).
Because NS_SWIFT_NAME and apinotes do not create symbols I guess.
I suggest using UInt value instead.
Should I file an issue somewhere about this? It seems like this is something that should work...?
I've filed FB13849129 about this, as requested in a WWDC session with Jonathan and Zoe.