First off, my code:
@interface Block : NSObject {
NSData *data;
NSInteger slice_count;
}
@property (readonly) NSData *data;
+ (Stopwatch *) runOldTestsUsingConfiguration:(TestConfiguration *)c;
- (Slice *) getSlice:(NSUInteger)idx;
@end
- (Slice *) getSlice:(NSUInteger)idx {
void *b = (void*)[data bytes] + idx*slice_count;
int len = [data length] / slice_count;
Slice *ret = [Slice alloc];
[ret initWithBytesNoCopy:b length:len freeWhenDone:NO];
return ret;
//NSString *temp2 = [data description];
//NSRange r = NSMakeRange(idx*slice_count, [data length] / slice_count);
//NSData *d = [data subdataWithRange:r];
//NSString *temp = [d description];
//Slice *s = [[Slice alloc] initWithBytesNoCopy:(void *)[d bytes] length:r.length freeWhenDone:NO];
//return s;
}
where Slice is a simple subclass of NSData.
For some reason I’m getting a run-time error that seems to indicate my Slice instance either a) isn’t actually a concrete instance (?) or b) something is going wrong in its inheritance and the message isn’t binding itself to Slice properly (almost certainly by my as yet unknown error).
The exact error I’m getting is this:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '***
initialization method -initWithBytes:length:copy:freeWhenDone:bytesAreVM:
cannot be sent to an abstract object of class Slice: Create a concrete instance!'
Can anyone help me out? I’ve tried just about everything I can think of (basic routines of which are detailed in the message call itself) and I am still coming up dry. What does it mean when it says ‘create a concrete instance’? Isn’t that what I’m doing when I alloc it?
Subclassing NSData is a lot more complicated than you would think. In most cases you are better off just writing a wrapper around NSData instead of a full subclass.