Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

multinode

macrumors regular
Original poster
Feb 4, 2011
150
0
I have a need to generate a command line app that will prompt the user to input 10 entries ... one at a time. The app must take each entry, convert it into an NSString, and add that NSString to an NSArray. After those 10 entries have been entered, the NSArray must be added to an existing NSDictionary.

I've never done a command line app in XCode, so I'm asking for some starting point help:

1. Command line debugging
2. Classes to use to service the keyboard entries.

Any pointers to relevant docs would be appreciated.
 
Last edited:
1. Command line debugging

man gdb


2. Classes to use to service the keyboard entries.
If you're familiar with scanf() and friends, you can use them. Or anything else in <stdio.h>. Or in any other C library.

You can tell Xcode to open the man page for any command, function, etc. Open man page is under Xcode's Help menu.


Any pointers to relevant docs would be appreciated.
See the basic Xcode project mgmt docs.

In Xcode Application templates (Xcode 3.*),
choose the Command Line Tool template,
from the Type popup
choose Foundation.


Example of a simple command-line Foundation tool:
Code:
#import <Foundation/Foundation.h>

int main( int argc, const char * argv[] )
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	NSString * cwd = nil;
	{
		char cbuf[ 2000 ];
		getcwd( cbuf, sizeof(cbuf) );
		cwd = [NSString stringWithUTF8String:cbuf];
	}

	NSLog( @"cwd: %@", cwd );

	NSLog( @"More stuff goes here." );

	[pool drain];
	return 0;
}
The C function getcwd() gets the working directory pathname in cbuf. The stringWithUTF8String: method converts it to an NSString. The returned NSString is NOT owned by the example code shown.

You will need to understand ownership if you use retain/release. You may find garbage collection worthwhile, as it can save some effort in managing ownership.
http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

You will also want to read the entire NSString class reference doc. Really. It has a lot of methods useful for converting to/from C strings.
 
Thanx CHOWN33. Back in the "olden days" if the program included getchar() a command line terminal would pop up. But I see now that the XCode console serves that purpose.

I misstated what I was looking for vis-a-vis debugging. I shouldn't have said that I was looking for command line debugging ... I was really looking to debug the command line app using XCode's debugger. And I see that that that works fine.

Your instructions regarding a new project helped.

man gdb



If you're familiar with scanf() and friends, you can use them. Or anything else in <stdio.h>. Or in any other C library.

You can tell Xcode to open the man page for any command, function, etc. Open man page is under Xcode's Help menu.



See the basic Xcode project mgmt docs.

In Xcode Application templates (Xcode 3.*),
choose the Command Line Tool template,
from the Type popup
choose Foundation.


Example of a simple command-line Foundation tool:
Code:
#import <Foundation/Foundation.h>

int main( int argc, const char * argv[] )
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	NSString * cwd = nil;
	{
		char cbuf[ 2000 ];
		getcwd( cbuf, sizeof(cbuf) );
		cwd = [NSString stringWithUTF8String:cbuf];
	}

	NSLog( @"cwd: %@", cwd );

	NSLog( @"More stuff goes here." );

	[pool drain];
	return 0;
}
The C function getcwd() gets the working directory pathname in cbuf. The stringWithUTF8String: method converts it to an NSString. The returned NSString is NOT owned by the example code shown.

You will need to understand ownership if you use retain/release. You may find garbage collection worthwhile, as it can save some effort in managing ownership.
http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

You will also want to read the entire NSString class reference doc. Really. It has a lot of methods useful for converting to/from C strings.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.