Convenience initializer not working: "unrecognized selector"
Convenience initializer not working: "unrecognized selector"
- Subject: Convenience initializer not working: "unrecognized selector"
- From: "K. Darcy Otto" <email@hidden>
- Date: Wed, 12 Mar 2008 20:25:48 -0700
I'm trying to create an initializer that allows me to combine
initialization and some setting of variables, but I get an error that
an "unrecognized selector" has been sent to the object. Here is what I
have so far:
Fraction.h:
#import <Cocoa/Cocoa.h>
@interface Fraction : NSObject {
NSInteger numerator;
NSInteger denominator;
}
@property(readwrite) NSInteger numerator;
@property(readwrite) NSInteger denominator;
-(id)initWith:(NSInteger)aNumerator over:(NSInteger)aDenominator;
@end
Fraction.m:
#import "Fraction.h"
@implementation Fraction
@synthesize numerator,denominator;
-(id)init
{
return [self initWith:1 over:1];
}
-(id)initWith:(NSInteger)aNumerator over:(NSInteger)aDenominator
{
if (self = [super init]){
self.numerator = aNumerator;
self.denominator = aDenominator;
}
return self;
}
@end
Now, I can do the following with no ill effects:
Fraction *frac = [[Fraction alloc] init];
frac.numerator = 2;
frac.denominator = 2;
But if I do this, I get the unrecognized selector error:
Fraction *frac1 = [Fraction initWith:2 over:2];
Can anyone explain the error or suggest a solution? Thanks.
_______________________________________________
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