Lucas Huang
Lucas Huang

Reputation: 4016

How to bind with struct in ReactiveCocoa with Objective-C

I will need to change the border color when meet certain condition like so, but I can't find a way to go through the compiler:

RAC(self.addrTextField.layer, borderColor) = [validateAddressSignal map:^ CGColorRef* (NSArray *array) {

    if (array.count) {
        return [UIColor greenColor].CGColor;
    }
    return [UIColor clearColor].CGColor;
}];

Upvotes: 0

Views: 218

Answers (1)

powerj1984
powerj1984

Reputation: 2226

The most elegant solution to a similar question asked on Reactive Cocoa's GitHub Issue tracker is the following posted by Erik Price:

@interface UIView (MyCategoryName)
- (void)setMyBorderColor:(UIColor *)color;
@end

@implementation UIView
- (void)setMyBorderColor:(UIColor *)color
{
    self.layer.borderColor = color.CGColor;
}
@end

// ...

RAC(myTextField, myBorderColor) = mySignalOfUIColors;

Basically, make it easy to bind the color by adding a category to UIView.

Upvotes: 1

Related Questions