On 2014 Aug 01, at 10:33, Sean McBride <s...@rogue-research.com> wrote:

> I've tried some similar permutations and they have 'fixed' the issue.  I have 
> about 50 xibs to fix now, so want to be sure I do this correctly. :)  I now 
> find myself questioning basic things. :)

I understand.  It would be nice to have to have a rock solid understanding of 
Cocoa Bindings with no hand-waving.  But I’m not sure that is possible.

> Which parts of a binding's keypath have to be KVO-compliant?  If all parts, 
> how can 'document' and 'managedObjectContext' even be in there at all?  Even 
> in interstitial object controllers as you described?

These are very good questions.  Unfortunately, I’m not able to justify my 
design pattern based on the Cocoa Bindings API documentation.  It’s one of 
those “It makes sense that this could work, and it does work, and it fixes a 
problem, and we need to ship” situations.

On 2014 Aug 01, at 10:51, Kyle Sluder <k...@ksluder.com> wrote:

> Because of the NSDocument lifecycle, you can presume these properties will 
> not change while the window is being shown.

Although that is theoretically dangerous, probably thousands of apps are 
dependent on it being true. 

> You could manually unbind the object controller in -windowDidClose: or in an 
> override of -setDocument:, and any other controllers bound through it will 
> hear about the change in a KVO-compliant way.

Looking through my code, although I never really gave this too much thought, it 
appears that I tend to -unbind: when in doubt.

It got me to thinking: I wonder if it is OK to sprinkle -unbind: messages in 
liberally?  Will there be a burp/exception if you -unbind: something more than 
once?  So I did a little test (results below) and it appears that the answer is 
“no”.  But the documentation for -unbind: does not state what happens if the 
indicated binding does not exist :(

I just filed a bug on that documentation: 17887226.  
“-[NSObject(NSKeyValueBindingCreation) unbind:] documentation does not state 
that it is OK to send this message indicating a binding which does not exist or 
has already been unbound. … Because Cocoa Bindings can be constructed in 
various ways, and because exceptions occur if bound objects disappear, 
developers often, sometimes unknowingly, -unbind: a binding more than once in 
edge cases.  That does not cause any trouble.  However, this behavior should be 
documented."

Jerry

*** Test Code ***

// Tags field is a custom control.  This code runs in -windowWillClose.

NSLog(@"tagsField = %@", tagsField) ;
NSLog(@"Before unbinding 1: %@", [tagsField infoForBinding:@"value"]) ;
[tagsField unbind:@"value"] ;
NSLog(@"Before unbinding 2: %@", [tagsField infoForBinding:@"value"]) ;
[tagsField unbind:@"value"] ;

*** Console Output ***

2014-08-01 11:31:43.060 MyApp[5631:303] tagsField = <SSYTokenField: 
0x6080001f4c00>
2014-08-01 11:31:43.062 MyApp[5631:303] Before unbinding 1: {
    NSObservedKeyPath = selectedStarkiTags;
    NSObservedObject = "<InspectorController: 0x6080001d0770>";
    NSOptions =     {
        NSAllowsEditingMultipleValuesSelection = 1;
        NSAlwaysPresentsApplicationModalAlerts = 0;
        NSConditionallySetsEditable = 1;
        NSConditionallySetsEnabled = 0;
        NSConditionallySetsHidden = 0;
        NSContinuouslyUpdatesValue = 0;
        NSMultipleValuesPlaceholder = "Multiple Values";
        NSNoSelectionPlaceholder = "No Selection";
        NSNotApplicablePlaceholder = "Not Applicable";
        NSNullPlaceholder = "No Tags";
        NSRaisesForNotApplicableKeys = 1;
        NSValidatesImmediately = 0;
        NSValueTransformer = "<null>";
        NSValueTransformerName = "<null>";
    };
}
2014-08-01 11:31:43.063 MyApp[5631:303] Before unbinding 2: (null)

No exceptions were logged.
_______________________________________________

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