我已经准备好将项目迁移到RAC,但是在绑定属性的更改时出现错误。

#import <UIKit/UIKit.h>
@interface XBXMLoginTextField : UIView
@property (nonatomic, assign) UIKeyboardType keyboardType;
@end

在.m文件中:
- (instancetype)init {
    if (self = [super init]) {

        [RACObserve(self, keyboardType) subscribeNext:^(UIKeyboardType x) {

        }];
    }
    return self;
}

有错误->
不兼容的块指针类型将'void(^)(UIKeyboardType)'发送到类型'void(^ _Nonnull)(id _Nullable __strong)的参数

我的代码有什么问题?

最佳答案

RACObserve返回一个信号,该信号将其整数值作为盒装NSNumber *触发,因此您需要使用其integerValue:

[RACObserve(self, keyboardType) subscribeNext:^(NSNumber *keyboardType) {
    NSLog(@"%ld", (long)keyboardType.integerValue);

    // Or any other user of keyboardType.integerValue, such as:
    if (keyboardType.integerValue == UIKeyboardTypeURL) {
        // Do stuff.
    }
}];

10-04 18:02