I have two classes:
1 - RMETest, an object which holds an array of RMEMatches.
2 - RMEMatch, an object which inherits from RMETest.
Right now, the following code refuses to compile because the line written in red is marked with "No known class method for selector 'alloc'"
I think my problem may have to do with circular references, but I'm not sure how to break them.
Here's some code.
I haven't actually gotten around to implementing RMEMatch yet, and as I was copying and pasting my code I realized that it's not going to work because _subtests isn't actually created anywhere, but my problem isn't with issues occurring at runtime: It's not even compiling right now!
Maybe I'm just up coding too late right now, but I can't think of why this wouldn't work.
1 - RMETest, an object which holds an array of RMEMatches.
2 - RMEMatch, an object which inherits from RMETest.
Right now, the following code refuses to compile because the line written in red is marked with "No known class method for selector 'alloc'"
I think my problem may have to do with circular references, but I'm not sure how to break them.
Here's some code.
Code:
// RMETest.h
#import <Foundation/Foundation.h>
@interface RMETest : NSObject
@property RMETest *parentTest;
// ...
// Other properties not relevant
// ...
- (RMETest *)initWithParentTest:(RMETest *)parentTest;
- (void)addNewMatch;
@end
Code:
// RMETest.m
#import "RMETest.h"
@class RMEMatch; // <- It needs to know that the class exists, but to avoid circular imports I'm using @class instead.
@interface RMETest () {
NSMutableArray *_subtests;
}
@end
@implementation RMETest
- (void)addSubtest:(RMETest *)subtest {
[_subtests addObject:subtest];
}
- (RMETest *)initWithParentTest:(RMETest *)parentTest {
if (self = [super init]) {
self.parentTest = parentTest;
}
return self;
}
- (void)addNewMatch {
[COLOR=RED] [self addSubtest:[[RMEMatch alloc] initWithParentTest:self]]; // This is the line causing problems! It says "No known class method for selector 'alloc'![/COLOR]
}
Code:
// RMEMatch.h
#import "RMETest.h"
@interface RMEMatch : RMETest
@end
// RMEMatch.m
#import "RMEMatch.h"
@implementation RMEMatch
@end
I haven't actually gotten around to implementing RMEMatch yet, and as I was copying and pasting my code I realized that it's not going to work because _subtests isn't actually created anywhere, but my problem isn't with issues occurring at runtime: It's not even compiling right now!
Maybe I'm just up coding too late right now, but I can't think of why this wouldn't work.
Last edited: