ios - 如何在 swift Xcode Playground 中获取用户输入

标签 ios swift xcode input

Swift 是否有像 Java、C# 或 C++ 这样的输入关键字或方法来在 Xcode Playground 中获取用户的输入?

最佳答案

swift 5.1

转到"file"->“新建”->“项目”->“macOS”->“命令行工具”。

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)
}

关于ios - 如何在 swift Xcode Playground 中获取用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59692937/

相关文章:

iphone - 如何为 iPhone 实现音量键快门?

ios - 在 Swift map 上显示路线

ios - 如何使用 UIBezierPath 修复无效上下文 0x0?

ios - 无法链接我的计时器按钮 (Xcode)

iphone - 如何删除 UITextView 的最后一个空行?

ios - 如何使用对象映射器 Swift 映射字典数组

ios - 如何在 Swift 中将字符串转换为 unicode(UTF-8) 字符串?

swift - 类型 'Int' 不符合协议(protocol) 'BooleanType'

xcode - Xcode 中的 "Non-breaking space (U+00A0) used instead of regular space"警告

iphone - 自定义 UITextField