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 8939939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:55:42+00:00 2026-06-15T10:55:42+00:00

I am trying to subclass NSInputStream and NSOutputStream to keep track of the command

  • 0

I am trying to subclass NSInputStream and NSOutputStream to keep track of the command I am passing to my server. This way, when I receive a response back from the server, I know which command it was a response to. When I try to set the command string in my subclass, I get an unrecognized selector error.

Subclasses:

PCFInputStream.h

#import <Foundation/Foundation.h>

@interface PCFInputStream : NSInputStream
@property (nonatomic, strong) NSString *command;
@end

PCFOutputStream.h

#import <Foundation/Foundation.h>

@interface PCFOutputStream : NSOutputStream
@property (nonatomic, strong) NSString *command;
@end

The .m files just have the command property synthesized so I can call setCommand:

Here is the class I am using these in:

 //instance vars in my class
 PCFInputStream *inputStream;
 PCFOutputStream *outputStream;


-(void)followClass:(id)sender
{
    CFReadStreamRef readStream;
    CFWriteStreamRef writeStream;
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef) SERVER_ADDRESS, PORT,     &readStream, &writeStream);
    inputStream = (__bridge_transfer PCFInputStream *)readStream;
    outputStream = (__bridge_transfer PCFOutputStream *)writeStream;
    [inputStream setDelegate:self];
    [outputStream setDelegate:self];
    [inputStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream setCommand:[NSString stringWithFormat:@"%d,%@",[sender tag], [class classTitle]]];
    [inputStream open];
    NSString *str = [NSString stringWithFormat:@"_ADD_CLASS*%@*%@*%@*%@;", [class CRN], deviceToken, [class classLink],[class courseNumber]];
    [outputStream setCommand:str];
    [outputStream open];
}

Here is the error I get when it runs the line

[inputStream setCommand:[NSString stringWithFormat:@"%d,%@",[sender tag], [class classTitle]]];

-[__NSCFInputStream setCommand:]: unrecognized selector sent to instance 0x1e691170
2012-12-01 21:56:20.777 PCF[15610:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFInputStream setCommand:]: unrecognized selector sent to instance 0x1e691170'
*** First throw call stack:
(0x3a1b73e7 0x39043963 0x3a1baf31 0x3a1b964d 0x3a111208 0xfa267 0x39585047 0x39584ffb 0x39584fd5 0x3958488b 0x39584d79 0x394a3441 0x3a18c941 0x3a18ac39 0x3a18af93 0x3a0fe23d 0x3a0fe0c9 0x3743733b 0x394ee291 0x100005 0xe7d48)
libc++abi.dylib: terminate called throwing an exception

Can someone suggest a simple solution for me? I tried wrapping a NSStreamInput instance and my NSString* command into another class, but that doesn’t work for my purposes.

Thanks!

  • 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-15T10:55:43+00:00Added an answer on June 15, 2026 at 10:55 am

    You can’t just cast an NSInputStream to a PCFInputStream. The object has to be created as a PCFInputStream, and CFStreamCReatePairWithSocketToHost doesn’t do that.

    You can just attach a command property to NSInputStream in a category by using an associated object. Here’s the category interface:

    @interface NSInputStream (PCFCommand)
    @property (nonatomic) NSString *pcf_command;
    @end
    

    You implement it like this:

    #import <objc/runtime.h>
    
    @implementation NSInputStream (PCFCommand)
    
    static int kPCFCommandKey;
    
    - (NSString *)pcf_command {
        return objc_getAssociatedObject(self, &kPCFCommandKey);
    }
    
    - (void)setPcf_command:(NSString *)pcf_command {
        objc_setAssociatedObject(self, &kPCFCommandKey, [pcf_command copy],
            OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to subclass DataList to accept a new Command from embedded LinkButtons. Here's
I'm trying to subclass an unmanaged statusbar window from my managed COM server using
I am trying to subclass the window that currently has focus. I do this
I'm trying to make a new CLLocation subclass. This is the skeleton: #import <UIKit/UIKit.h>
In Django, I am trying to derive (subclass) a new form from ModelForm form
I am trying to subclass a progress control in a dialog box using this
I'm trying to subclass numpy.complex64 in order to make use of the way numpy
Ok I'm stumped again! This should be easy though ;-) I'm trying to subclass
I'm trying to add a subclass of View to my activity_main.xml like this .
I'm trying to override the printed output from an Exception subclass in Python after

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.