On Sep 7, 2014, at 7:02 AM, Ken Thomases <k...@codeweavers.com> wrote:

> On Sep 7, 2014, at 5:15 AM, Daryle Walker <dary...@mac.com> wrote:
> 
>> Right now, the menu item that holds the submenu where the overflow menu 
>> items go is always visible. I was thinking of controlling its visibility 
>> with Cocoa Bindings. I select the menu item in the Interface Builder part of 
>> Xcode, go to the Bindings Inspector, reveal the Hidden attribute settings, 
>> and set the binding to my app’s delegate. Under the Model Key Path, I put 
>> “self.my2ndCoordinator.overflowArray”. Now, that’s an array and I need a 
>> Boolean. I tried “.count” and “.@count” at the end, and neither worked.
> 
> What does "neither worked" mean?  What happened?

Putting “my2ndCoordinator.overflowArray” gives me a red exclamation stop-sign 
in the text field with the tool-tip text: “The Hidden expects to be bound to an 
object of type NSNumber, but my2ndCoordinator.overflowArray is of type 
NSArray.” Appending a “.@count” gives a grey exclamation stop-sign with a 
tool-tip of: “Xcode cannot resolve the entered keypath”.  Now when I use 
“.count” I get no complaints, although I did before writing the first message. 
(Did leaving out the “self.” make a difference?) I do end up crashing ("An 
uncaught exception was raised” followed by “[<__NSArrayM 0x60000004a770> 
addObserver:forKeyPath:options:context:] is not supported. Key path: count”).

> ".@count" should work.  ".count" would not.  That effectively attempts to 
> construct an array by asking each _element_ of overflowArray for its "count" 
> property, which is always the way that KVC on arrays works.  This will 
> probably fail because the elements don't have a count property and even it 
> succeeds, it would result in an array which is not an appropriate result for 
> the hidden binding.
> 
> (Also, starting a key path with "self." is just redundant.)
> 
>> Even then, I still need to stick in the “> 0” part somewhere (unless 
>> Bindings does the zero vs. non-zero to Boolean conversion C does).
> 
> I don't know that I'd describe it as bindings "doing" that "conversion", but, 
> yes, in a boolean context, 0 means false and non-zero means true.  Since you 
> presumably want the menu to be hidden when the count is 0, you want to use 
> the NSNegateBoolean value transformer set on the binding.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to