当 return 值的类型为 CGFloat 时,如何使用 ReactiveCocoa 发送 Keypath
How to use ReactiveCocoa to sendKeypath when the type of return value is CGFloat
self.subscription = [[[RACObserve(photoModel, fullsizedData) filter:^BOOL(id value) {
return value != nil;
}]map:^id(id value) {
return [NSNumber numberWithFloat:1.0f];
} ]setKeyPath:@keypath(self.imageView.layer,borderWidth)onObject:self.imageView];
错误日志是:
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<UIImageView 0x7b1a8510> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key cornerRadius.
而且我认为如果有另一种方法来响应类型为 float、int 等的值。我会接受它
您应该使用字符串而不是 @keypath
宏。
[... setKeyPath:"layer.borderWidth" onObject:self.imageView];
或者你可以使用RAC宏,更清晰。
RAC(self.imageView, layer.borderWidth)
= [[RACObserve(photoModel, fullsizedData) filter:^BOOL(id value) {
return value != nil;
}] map:^id(id value) {
return @1.0f;
}];
self.subscription = [[[RACObserve(photoModel, fullsizedData) filter:^BOOL(id value) {
return value != nil;
}]map:^id(id value) {
return [NSNumber numberWithFloat:1.0f];
} ]setKeyPath:@keypath(self.imageView.layer,borderWidth)onObject:self.imageView];
错误日志是:
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<UIImageView 0x7b1a8510> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key cornerRadius.
而且我认为如果有另一种方法来响应类型为 float、int 等的值。我会接受它
您应该使用字符串而不是 @keypath
宏。
[... setKeyPath:"layer.borderWidth" onObject:self.imageView];
或者你可以使用RAC宏,更清晰。
RAC(self.imageView, layer.borderWidth)
= [[RACObserve(photoModel, fullsizedData) filter:^BOOL(id value) {
return value != nil;
}] map:^id(id value) {
return @1.0f;
}];