Problem chaining initialization methods
Problem chaining initialization methods
- Subject: Problem chaining initialization methods
- From: Mike Chambers <email@hidden>
- Date: Sun, 3 Jan 2010 18:36:14 -0800
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 (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