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;
}