Reputation: 5698
So I have a view that I want hidden depending on a BOOL
I do this by Cocoa Bindings
[view bind:@"hidden" toObject:self withKeyPath:@"someBOOL" options:bindingOptions];
My problem is now I want another BOOL to be bound to the view as well.
So if either of these BOOLs return YES
, I want the view
to be hidden
[view bind:@"hidden" toObject:self withKeyPath:@"someBOOL2" options:bindingOptions];
The problem is that it looks like by default, having two BOOL bindings to the same view defaults to a logical AND operation, and so it doesn't matter if either someBOOL
or someBOOL2
evaluate to YES
if the other one doesn't also evaluate to YES
So does anybody know if there's a way to make it so these programmatic boolean bindings use the logical OR operator?
This is the only relevant documentation and information I could find: https://developer.apple.com/library/content/documentation/Cocoa/Reference/CocoaBindingsRef/Concepts/BindingTypes.html
Multiple-Value Bindings
Multiple-value bindings allow multiple bindings to be created for a single binding. Creating a binding with the first binding automatically causes a second binding to be exposed, and so on.
For example, if you bind to the enabled binding, a binding called enabled2 is exposed. If you bind enabled2, the object will expose enabled3, and so on. All these binding values are then used together in returning the final value of the binding.
Multiple-value bindings are always read-only.
There are four variations of multiple-value bindings.
Multiple-Value Boolean Bindings Multiple-value Boolean bindings are used to determine if an object is editable, hidden, or enabled. The resulting value of the binding is derived by forming the logical AND or logical OR of the values of the exposed bindings. The logical operation used depends on the specific binding.
Upvotes: 1
Views: 707
Reputation: 90641
For the second binding as you've shown it, you're still using the name "hidden". That replaces the first binding. If you want to use multiple-value bindings, the second one needs to using the binding name "hidden2".
As noted by @Willeke, the hidden binding uses a logical OR for multiple-value bindings. Good thing that's what you want, because, no, you can't change it. :)
Upvotes: 4