简体   繁体   中英

How to get input from the user in swift Xcode playgroud

swift 是否有像 Java 或 C# 或 C++ 这样的输入关键字或方法来从 Xcode 操场中的用户那里获取输入?

Swift 5.1

Go to "File" -> "New" -> "Project" -> "macOS" -> "Command Line Tool".

import Foundation

func input() -> String {
    let keyboard = FileHandle.standardInput
    let inputData = keyboard.availableData
    return String(data: inputData, encoding:String.Encoding.utf8.rawValue)!
}

if let number1 = readLine() , let number2 = readLine() {


var IntNum1 = Int(number1)
var IntNum2 = Int(number2)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM