bobo pei
bobo pei

Reputation: 52

How to bind enumerate variable changed in objc?

I'm ready to migrate my project to RAC,but there is a error that when I want to bind a property's change.

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

In .m file:

- (instancetype)init {
    if (self = [super init]) {

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

        }];
    }
    return self;
}

There is an error -> Incompatible block pointer types sending 'void (^)(UIKeyboardType)' to parameter of type 'void (^ _Nonnull)(id _Nullable __strong)'

What's wrong with my code?

Upvotes: 1

Views: 48

Answers (1)

danielhadar
danielhadar

Reputation: 2161

RACObserve returns a signal that fires its integer value as a boxed NSNumber *, so you need to make use of its 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.
    }
}];

Upvotes: 1

Related Questions