快速错误: Int is not convertible to 'DictionaryIndex<Int,Int>'

标签 swift

当我从 Xcode 6 beta 4 切换到 beta 5 时,我在引用我的 plays 变量时收到此错误(Int 无法转换为“DictionaryIndex”)。我不知道如何解决这个问题。

这是代码块:

    var plays = Dictionary<Int,Int>()
    var done = false
    var aiDeciding = false


//Function that says what to do if a UIButton is clicked:

@IBAction func UIbuttonClicked(sender:UIButton) {
    if !plays[sender.tag] && !aiDeciding && !done {
        setImgforCircle(sender.tag, player:1)
        thinkingLabel.hidden = true
        thinkingLabel2.hidden = true
        thinkingLabel3.hidden = true

    }

最佳答案

我认为这只是一个欺骗性的错误消息,实际的错误在

if !plays[sender.tag]

相反,它应该是

if plays[sender.tag] != nil

关于快速错误: Int is not convertible to 'DictionaryIndex<Int,Int>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25169457/

相关文章:

swift - 如何替换字符串中的特定字符?

ios - tableview 单元格中的 UIButton 更改文本

swift NSEvent 不工作

swift - 实现 Razorpay

ios - 使用 Swiftly JSON 解析 JSON

swift 警告 : 'weak' should not be applied to a property declaration in a protocol

ios - 当 ScrollView subview 不在屏幕上时手势识别器不工作

ios - 更改整个应用程序中的字体大小

ios - 带有未在后台调用的请求 block 的 URLSession.datatask

ios - 在 Swift 3.0 中将 [String, String] 添加到没有 Optional\"(Help)"的 UIAlertController 消息