swift 2 中的用户输入

User input in swift 2

我是一名新程序员,目前正在努力学习教程。 我一直在尝试让用户输入我的代码,我在网上找到的每个示例似乎都表明这是正确的语法。显然我做错了什么:) Xcode 报告:"Use of Unresolved indentifier 'input'" 提前致谢。

import Foundation

var diceRoll = Int(arc4random_uniform(100) + 1)
print("\(diceRoll)")

print("Enter a number between 1 and 100.")

var userinput=input()
let intinput=userinput.toint()

if intinput == diceRoll {print("correct guess")}
  if intinput < diceRoll {print("too low")}
   else if intinput > diceRoll {print("too high")}
import Foundation

var diceRoll = Int(arc4random_uniform(100) + 1)
print("\(diceRoll)")

var i = 0
repeat {
    print("Enter a number between 1 and 100:")

    if let inputString = readLine() {
        if let inputNumber = Int(inputString) {
            i = inputNumber
        }
    }

} while i < 1 || i > 100
/* console output
24
Enter a number between 1 and 100.
0
Enter a number between 1 and 100.
101
Enter a number between 1 and 100.
100
Program ended with exit code: 0
*/

.

func readLine(stripNewline stripNewline: Bool = default) -> String?

Returns Characters read from standard input through the end of the current line or until EOF is reached, or nil if EOF has already been reached.

If stripNewline is true, newline characters and character combinations will be stripped from the result. This is the default.

Standard input is interpreted as UTF-8. Invalid bytes will be replaced by Unicode replacement characters.