-4

How do I read input from console in swift as 'scanf() in c' and 'input() in python'.

I have tried

var ans = readline()
print(ans) 

and its not working

Thanks.

wahid_abdul
  • 156
  • 2
  • 9
  • 4
    Possible duplicate of [Input from the keyboard in command line application](http://stackoverflow.com/questions/24004776/input-from-the-keyboard-in-command-line-application) – Alexander Mar 01 '17 at 06:40
  • You clearly haven't googled this before posting here. – Alexander Mar 01 '17 at 06:40

1 Answers1

3

readLine is the right thing to use. The only possible reason why this does not work is that you're running it in a playground or some other place where the command prompt does not exist.

To make this work, simply create a new command line tool project. Go to "File" -> "New" -> "Project" -> "macOS" -> "Command Line Tool".

enter image description here

Now readLine should work.

Sweeper
  • 213,210
  • 22
  • 193
  • 313