以下代码在 iOS 项目中运行良好,但在 iOS 游乐场中失败。知道为什么,除了“这可能是一个错误”吗?注意:您需要打开 Playground 调试区域才能看到消息:“'subscript' 的重载存在这些部分匹配的参数列表:(Int)、(Range)、(Range)、(Self.Index)”
import GameplayKit
import UIKit
let countries = ["france", "germany", "italy"]
let randomIndex = GKRandomSource.sharedRandom().nextIntWithUpperBound(3)
let chosenCountry = countries[randomIndex].uppercaseString
print(chosenCountry)
同样,相同的代码在常规 iOS 项目中也能正常工作。看起来有些东西对Int
and感到困惑UInt
,因为如果我进行类型转换randomIndex
,Int
它就可以正常工作。