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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:20:17+00:00 2026-06-10T16:20:17+00:00

I am a newbie in Objective-C. I am trying to learn how to work

  • 0

I am a newbie in Objective-C. I am trying to learn how to work with NSStream. I just used simple code from Apple Support. This code should open a stream from a file in my Desktop and show a simple message when the delegate is called by iStream. At the end of the code, I can see the status is correct, but the delegate never gets called. What am I missing?

#import <Foundation/Foundation.h>

@interface MyDelegate: NSStream <NSStreamDelegate>{
}

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode ;

@end

@implementation MyDelegate

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode  {
    NSLog(@"############# in DELEGATE###############");
}

@end

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        MyDelegate* myDelegate=[[MyDelegate alloc]init];
        NSInputStream* iStream= [[NSInputStream alloc] initWithFileAtPath:@"/Users/Augend/Desktop/Test.rtf"];

        [iStream setDelegate:myDelegate];

        [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
                           forMode:NSDefaultRunLoopMode];
        [iStream open];

        NSLog(@" status:%@",(NSString*) [iStream streamError]);
    }
    return 0;
}
  • 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-10T16:20:19+00:00Added an answer on June 10, 2026 at 4:20 pm

    The run loop isn’t running long enough for the delegate method to be called.

    Add:

    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
    

    right after you open the stream. This is only necessary in a program without a GUI — otherwise the run loop would be spun for you.

    If you want to be absolutely sure that stream:handleEvent: has been called before exiting, set a (global) flag in that method and put the runUntilDate: in a while loop that tests for the flag:

    while( !delegateHasBeenNotified ){
         [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is from an Objective-C newbie, so please bear with me. I'm trying
I am newbie to objective-c.So apologies in advance if this question sounds simple.As we
I am newbie of objective-c and i got this crazy problem… for low precision
I'm a newbie doing Objective-C, coming from Flex/Actionscript development. I have an iPhone app
I'm just a newbie of Objective C iPhone programming... I see a lot of
preemptive sorry for the newbie question. I'm trying to load strings from a resource
I'm a complete newbie to Objective-C, coming from a background of PHP, assorted dialects
I don't get it. i am a newbie to objective c and i just
Objective-C newbie question. Given the following (fictional) code: id mysteryObject = [anotherObject mysteriousMethod]; How
I came from objective-c and I am an Android newbie. I am using following

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.