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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to