Member Avatar for Nathan_6

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
"
Member Avatar for Nathan_6

Any help is appreciated in advance.

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

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.