我有这个表达式,它返回一个UInt32
:
let randomLetterNumber = arc4random()%26
我希望能够在这个 if 语句中使用数字:
if letters.count > randomLetterNumber{
var randomLetter = letters[randomLetterNumber]
}
这个问题是控制台给了我这个
Playground execution failed: error: <REPL>:11:18: error: could not find an overload for '>' that accepts the supplied arguments
if letters.count > randomLetterNumber{
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
问题是UInt32
无法与Int
. 我想转换randomLetterNumber
为Int
. 我努力了:
let randomLetterUNumber : Int = arc4random()%26
let randomLetterUNumber = arc4random()%26 as Int
这两个原因could not find an overload for '%' that accepts the supplied arguments.
如何转换值或在 if 语句中使用它?