Search code examples
swiftinputreadline

(Swift) Is there a way to read user's input on the same line as the question?


My code currently looks like this:

Enter your number:

25

I would like my code to look like this:

Enter your number: 25

In other words, I would like to read an input from the user on the same line as the prompt. Thanks


Solution

  • Yes by changing the terminator of the print call

    print("Enter your number: ", terminator: "")