Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JLB-UK

macrumors regular
Original poster
Oct 21, 2009
136
0
UK
Hi,

I get the following warning when calling the initWithNumberOfSides from the init method, which is in a init override in a custom class I have created.

Code:
 'PolygonShape' may not respond to '-initWithNumberOfSides:minimumNumberOfSides:maximumNumberOfSides:'

The code is as follows

Code:
- (id)init { 
	if (self = [super init]) {
		[self initWithNumberOfSides:4 minimumNumberOfSides:3 maximumNumberOfSides:10];
	}
	return self;
}


- (id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min maximumNumberOfSides:(int)max; { 
	if (self = [super init]) {
		[self setMinimumNumberOfSides:min];
		[self setMaximumNumberOfSides:max];
		[self setNumberOfSides:sides];
	}
	return self;
}

The warning error appears however, the code still runs and completes correctly. Could anyone provide any advice on resolving the warning message?

Thanks for the help
 
Thank you! Thought I had, but misspelt it! Problem solved! Thanks for your help
 
chown's comment is correct.

You should read up on the concept of the designated initializer in the Objective-C 2.0 programming language guide.

You should probably fix it like this

Code:
- (id)init { 
	if ((self = [self initWithNumberOfSides:4 minimumNumberOfSides:3 maximumNumberOfSides:10])) {
	}
	return self;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.