0

Hi,

I am working on a blackjack game as a person learning swift.
Due to my need to learn the basics of swift before jumping into learning how the view controllers and other mobile-app specific details work, I am making this game in a playground.

I wrote a function that is intended to get a user's input from the console, but the function does not wait for the user to enter his input. Instead, it returns an empty string and lets the program go on without letting the user enter in the appropriate input.

Here is my function (that gets successfully called within the playOneGame function):



    func input() -> String
    {
        print("Checkpoint 1")
        let input = readLine(stripNewline: true)
        print("Checkpoint 2")
        if (input != nil)
        {
            return input!
        }

        else
        {
            return ""
        }

    }

and as one can see with this output, it does not wait for the user to enter his input in:
"
Checkpoint 1
Checkpoint 2
"

Edited by Nathan_6

1
Contributor
1
Reply
8
Views
1 Year
Discussion Span
Last Post by Nathan_6
0

Any help is appreciated in advance.

Could anyone please provide some input how to solve this problem?

Thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.