• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem chaining initialization methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Problem chaining initialization methods
      • From: Rick Genter <email@hidden>
    • Re: Problem chaining initialization methods
      • From: Dave DeLong <email@hidden>
  • Prev by Date: Re: Question about garbage collection
  • Next by Date: Re: Problem chaining initialization methods
  • Previous by thread: Re: Revolving scoreboard
  • Next by thread: Re: Problem chaining initialization methods
  • Index(es):
    • Date
    • Thread