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