I am having a weird problem when chaining initializers in a class
which extends NSPredicateEditorRowTemplate.

If I call the

-(id)initWithArray:(NSArray *)arr forKeyPath:(NSString *)keyPath
andTitle:(NSString *)title

initializer directly when initializing, then everything works.
However, if I call the :

-(id)initWithArray:(NSArray *)arr forKeyPath:(NSString *)keyPath

which then calls the default initializer

-(id)initWithArray:(NSArray *)arr forKeyPath:(NSString *)keyPath
andTitle:(NSString *)title

Then the initialization fails. The [super initWithLeftExpressions ...]
call returns nil.

I am guessing I am not understanding something basic around
initialization chaining, but everything I have looked at online seems
to suggest I am doing this correctly.

So, does anyone see anything obviously wrong with how I am chaining
the initializers below?

-(id)initWithArray:(NSArray *)arr forKeyPath:(NSString *)keyPath
{
        NSString *capPath = [keyPath capitalizedString];
        if(![self initWithArray:arr forKeyPath:keyPath andTitle: capPath]);
        {
                return nil;
        }
        
        return self;
}

//designated initializer
-(id)initWithArray:(NSArray *)arr forKeyPath:(NSString *)keyPath
andTitle:(NSString *)title
{       
        NSMutableArray *expressions = [NSMutableArray arrayWithCapacity:[arr 
count]];
        for(NSString *s in arr)
        {
                [expressions addObject:[NSExpression 
expressionForConstantValue:s]];
        }       
        
        //this fails if called from -(id)initWithArray:(NSArray *)arr
forKeyPath:(NSString *)keyPath initializer
        self = [super initWithLeftExpressions:[NSArray
arrayWithObjects:[NSExpression expressionForKeyPath:keyPath], nil]
                                          rightExpressions:expressions
                                                          
modifier:NSDirectPredicateModifier
                                                         operators:[NSArray 
arrayWithObjects:
                                                                                
[NSNumber numberWithInt:NSEqualToPredicateOperatorType],
                                                                                
[NSNumber numberWithInt:NSNotEqualToPredicateOperatorType], nil]
                                                           
options:NSCaseInsensitivePredicateOption];   
        
        if(!self)
        {
                return nil;
        }

        //...
        
        return self;
}

mike
_______________________________________________

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