FROM : K. Darcy Otto
DATE : Thu Mar 13 04:25:48 2008
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.
DATE : Thu Mar 13 04:25:48 2008
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.
| Related mails | Author | Date |
|---|---|---|
| K. Darcy Otto | Mar 13, 04:25 | |
| Chris Suter | Mar 13, 04:32 | |
| Adam Leonard | Mar 13, 04:48 |






Cocoa mail archive

