Re: NSTableView Binding NSSortDescriptor
Re: NSTableView Binding NSSortDescriptor
- Subject: Re: NSTableView Binding NSSortDescriptor
- From: Ben <email@hidden>
- Date: Sat, 26 Nov 2011 00:51:51 +0000
Ah yes thank you Quincey, that makes total sense now. I have been on honeymoon for the last 8 months and I'm a little bit rusty. I am just trying to get my head around bindings xcode 4 & ARC.
On 25 Nov 2011, at 21:51, Quincey Morris wrote:
> On Nov 25, 2011, at 13:21 , Ben wrote:
>
>> @property (readonly, strong, nonatomic) IBOutlet NSArray *sortDescriptorArray; (plus @synthesize it in the implementation)
>>
>>
>> In my applicationDidFinishLaunching method I have...
>>
>>
>> NSSortDescriptor * sd = [[NSSortDescriptor alloc] initWithKey:@"address" ascending:YES];
>> sortDescriptorArray = [NSArray arrayWithObject:sd];
>
> Well, one obvious difficulty is that if the NIB file containing the table is loaded before applicationDidFinishLaunching, this code won't work because it's not KVO compliant. The correct code would be:
>
> self.sortDescriptorArray = [NSArray arrayWithObject:sd];
>
> if you took away the 'readonly' attribute, or:
>
> [self willChangeValueForKey: @"sortDescriptorArray"];
> self.sortDescriptorArray = [NSArray arrayWithObject:sd];
> [self didChangeValueForKey: @"sortDescriptorArray"];
>
> if you didn't.
>
> However, it would make more sense (and solve the above difficulty) to put the code in the getter instead:
>
> - (NSArray*) sortDescriptorArray {
> if (!sortDescriptorArray)
> sortDescriptorArray = …;
> return sortDescriptorArray;
> }
>
> The other odd thing in your code is the 'IBOutlet' annotation on the property. You don't need or want to mark it as an outlet unless you're going to connect it to something in the NIB file. If you did connect it to something in the NIB file, then you don't want to put code to initialize it in the delegate.
>
> There's a very loose sense in which outlets and bindings are mutually exclusive (although there are specific scenarios where you end up with both).
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden