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

  • SEARCH
  • Home
  • 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 7858513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:28:27+00:00 2026-06-02T21:28:27+00:00

I’m learning Cocoa… I tried different way to do that but I’m still in

  • 0

I’m learning Cocoa…
I tried different way to do that but I’m still in the black…

I have this method in my implementation:

- (void)closeStream:(NSStream *)theStream {

    [theStream close];
    [theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

}

How can I call it from an IBAction in my @synthetize?

    - (IBAction)connect:(id)sender {

        if ([[connectNOK stringValue] isEqualToString:@"Disconnected"]) {

            [connectButton setTitle:@"Disconnect"];   
            NSString * hostFromField = [hostField stringValue];

            CFReadStreamRef readStream;
            CFWriteStreamRef writeStream;
            CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)hostFromField, [portField intValue], &readStream, &writeStream);
            inputStream = (NSInputStream *)readStream;
            outputStream = (NSOutputStream *)writeStream;

            [inputStream setDelegate:self];
            [outputStream setDelegate:self];

            [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
            [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

            [inputStream open];
            [outputStream open];

        } else {

            [connectButton setTitle:@"Connect"];

            // I want to call this method here   
        }
    }
  • 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-02T21:28:28+00:00Added an answer on June 2, 2026 at 9:28 pm

    If the closeStream: method is defined in the same class than the connect: method, you’ll have to use:

    [ self closeStream: someStream ];
    

    Where someStream is the NSStream object you need to pass.

    The self keyword refers to the current instance of the class.

    If you don’t know that, or what it means, I suggest you take a look at the Objective-C language basics before trying to do/code anything, and maybe after, the complete language reference.

    EDIT:

    I can see in your code that your connect: method «toggles» the connection based on the value of a button label.

    This is not a very good design, for you to know, but you’ll have other problems here.

    I guess you want to close the input and output streams, if necessary.
    The problem is, when the connect method is called a second time, the inputStream and outputStream variables are not accessible anymore, as they are local variables.

    You probably need to store them as instance variables instead, so you can refer to them later on.

    Once again, it seems you really should start by reading some documentation about programming principles, as well as some Object-Oriented programming principles.
    Don’t try to go too fast. Knowledge is the key to everything, so start by reading the documentation I mentioned before.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.