|
From: | Marc Brünink |
Subject: | Re: coding for standard in |
Date: | Tue, 12 Dec 2006 10:49:27 +0100 |
User-agent: | Thunderbird 1.5 (X11/20060113) |
tgate wrote:
I was looking in to this area too - it's still on my todo list - if you get anywhere please let me know I'll be interested on how to do this myself.Okay, I'm not sure if this is really the proper way of doing this, but it seems to work...int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"-----> %s",argv[1]); NSString *script = [NSString stringWithCString: argv[1]]; NSFileHandle *fh = [[NSFileHandle alloc] init]; fh = [NSFileHandle fileHandleForReadingAtPath: script]; NSData *inData = [[NSData alloc] init]; inData = [fh readDataToEndOfFile];NSString *myString = [[NSString alloc] initWithData: inData encoding: NSUTF8StringEncoding];NSLog(@"\n%@\n", myString); [pool release]; return 0; }
Hi,please do not be offended, but you did not understand memory management in Obj-C.
You do not need these lines: NSFileHandle *fh = [[NSFileHandle alloc] init]; NSData *inData = [[NSData alloc] init]; Nevertheless you've to declare the ivars, NSFileHandle *fh; NSData *inData;but you do not have to alloc-init them. fileHandleForReadingAtPath: and readDataToEndOfFile]; both return autoreleased objects, which means all the alloc-init stuff is done for you. Please re-read your favorite Obj-C manual. Espacially the sections about memory management.
Ciao Marc
[Prev in Thread] | Current Thread | [Next in Thread] |