I’d like to make a subclass of NSInputStream. Simply, I tried to code just like the following,
@interface SeekableInputStream : NSInputStream
{
NSUInteger startOffset;
NSUInteger totalReadLen;
}
- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len;
- (BOOL)getBuffer:(uint8_t **)buffer length:(NSUInteger *)len;
- (BOOL)hasBytesAvailable;
- (void)open:(NSUInteger)offset;
@end
and, I used the class like the following.
SeekableInputStream *stm = [[SeekableInputStream alloc] initWithURL:url];
Then, in runtime, I could meet the following error message.
-[SeekableInputStream initWithURL:]: unrecognized selector sent to instance 0x10018ff30
I didn’t override initWithURL for using parent’s method purposely.
Based on my knowledge, derived class can uses method of parent class, isn’t it?
Can not an extension method like initWithURL be inherited?
Is there anybody inform me how to do subclassing of NSInputStream?
From NSStream.h
As you can see, there are no initWithURL function. So, your
superdo not work, because it really don’t exist. Like MrTJ says, it is a category class. It is defined in:So, I think if you use it in your subclass, it can work.
You need to import the category. Remember you CAN’T subclass a category, just overwrite it and can’t call then (or if can, I don’t know how)