Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:39:00+00:00 2026-06-01T11:39:00+00:00

I’d like to make a subclass of NSInputStream. Simply, I tried to code just

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:39:01+00:00Added an answer on June 1, 2026 at 11:39 am

    From NSStream.h

    // NSStream is an abstract class encapsulating the common API to NSInputStream and NSOutputStream.
    // Subclassers of NSInputStream and NSOutputStream must also implement these methods.
    @interface NSStream : NSObject
    - (void)open;
    - (void)close;
    
    - (id <NSStreamDelegate>)delegate;
    - (void)setDelegate:(id <NSStreamDelegate>)delegate;
     // By default, a stream is its own delegate, and subclassers of NSInputStream and NSOutputStream must maintain this contract. [someStream setDelegate:nil] must restore this behavior. As usual, delegates are not retained.
    
    - (id)propertyForKey:(NSString *)key;
    - (BOOL)setProperty:(id)property forKey:(NSString *)key;
    
    - (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
    - (void)removeFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
    
    - (NSStreamStatus)streamStatus;
    - (NSError *)streamError;
    @end
    
    // NSInputStream is an abstract class representing the base functionality of a read stream.
    // Subclassers are required to implement these methods.
    @interface NSInputStream : NSStream
    - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len;
    // reads up to length bytes into the supplied buffer, which must be at least of size len. Returns the actual number of bytes read.
    
    - (BOOL)getBuffer:(uint8_t **)buffer length:(NSUInteger *)len;
    // returns in O(1) a pointer to the buffer in 'buffer' and by reference in 'len' how many bytes are available. This buffer is only valid until the next stream operation. Subclassers may return NO for this if it is not appropriate for the stream type. This may return NO if the buffer is not available.
    
    - (BOOL)hasBytesAvailable;
    // returns YES if the stream has bytes available or if it impossible to tell without actually doing the read.
    @end
    

    As you can see, there are no initWithURL function. So, your super do not work, because it really don’t exist. Like MrTJ says, it is a category class. It is defined in:

    // The NSInputStreamExtensions category contains additional initializers and convenience routines for dealing with NSInputStreams.
    @interface NSInputStream (NSInputStreamExtensions)
    - (id)initWithURL:(NSURL *)url NS_AVAILABLE(10_6, 4_0);
    

    So, I think if you use it in your subclass, it can work.

    #import <Foundation/NSStream.h>
    

    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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.