tags:

views:

490

answers:

3

Is there anyway we can take input from command line in Objective-C, the way we can take in C/C++

e.g;

int inputVariableName;

cin>>inputVariableName;

+2  A: 

Sure. Compile your code as Objective-C++.

This is typically as easy as renaming the file from having a .m suffix to a .mm suffix.

Documentation is included with the Xcode tools as to the details of Objective-C++.

bbum
I don't know about Objective-C++ but is there any native way in Objective-C?
itsaboutcode
Objective-C++ is native Objective-C. But, yes, you can do this in pure Objective-C. See the NSFileHandle class.
bbum
+6  A: 
scanf("%i", userInput);

just as you would in c

To get Objective-C objects from the input, simple convert them after reading them in:

NSNumber * number = [nsnumber numberwithint:useriput];

ennuikiller
Oh yah! what a dum i am lox
itsaboutcode
But i have another question, though it can solve my problem by now but if have an Object which has NSString or NSNumber objects within it, how i can take input for them? Since there is there no way scanf can handle these kind of objects?
itsaboutcode
I think i got answer to my second question on the following ur:http://stackoverflow.com/questions/493688/objective-c-how-do-i-do-console-input
itsaboutcode
+1  A: 

As bbum mentioned, you can use NSFileHandle to get access to stdin. If you just want to read the command line arguments, you can get them from [[NSProcessInfo processInfo] arguments]. It's also worthwhile to know what else NSProcessInfo can tell you.

NSResponder