swift - 将 AWS DynamoDB 代码更新到 Swift 3 会导致错误

标签 swift amazon-web-services swift3 amazon-dynamodb

Swift 2.x代码如下:

extension Table {

func produceOrderedAttributeKeys(model: AWSDynamoDBObjectModel) -> [String] {
    let keysArray = Array(model.dictionaryValue.keys)
    var keys = keysArray as! [String]
    keys = keys.sort()

    if (model.classForCoder.respondsToSelector("rangeKeyAttribute")) {
        let rangeKeyAttribute = model.classForCoder.rangeKeyAttribute!()
        let index = keys.indexOf(rangeKeyAttribute)
        if let index = index {
            keys.removeAtIndex(index)
            keys.insert(rangeKeyAttribute, atIndex: 0)
        }
    }
    model.classForCoder.hashKeyAttribute()
    let hashKeyAttribute = model.classForCoder.hashKeyAttribute()
    let index = keys.indexOf(hashKeyAttribute)
    if let index = index {
        keys.removeAtIndex(index)
        keys.insert(hashKeyAttribute, atIndex: 0)
    }
    return keys
}

}

行:

if (model.classForCoder.respondsToSelector("rangeKeyAttribute")) {

使用 Swift 旧版编译器会发出警告“不推荐使用 Objective-C 的字符串文字;使用 #selector”

它提供了一个修复选项,将其更改为:

if (model.classForCoder.responds(to: #selector(AWSDynamoDBModeling.rangeKeyAttribute))) {

但是我收到一条错误消息:

无法调用非函数类型“((Selector) -> Bool)!”的值!

我一直在疯狂地谷歌搜索,试图弄清楚如何使这个 Swift 3 兼容,但没有成功。一些 Swift 3 专业知识将不胜感激!

最佳答案

您必须确保您的类派生自 NSObject。

(实际上我不确定,我在这个链接中找到了这个答案 here )

关于swift - 将 AWS DynamoDB 代码更新到 Swift 3 会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868793/

相关文章:

swift - 如何从另一个 parent 那里过滤 Swift 中的 Firebase 数据?

swift - 无法在 swift 3 中使用 SDWebImage 为 gif 制作动画

ios - 给 UITextField 添加边框

amazon-web-services - AWS 灾难恢复以及备份和存储

swift - 在 Swift 3 中仅修剪字符串末尾的尾随空格

swift - 为什么 Swift 中的公共(public)类/结构需要显式公共(public)初始化程序?

xcode - swift 博客中的气球演示错误

java - AWS Java 开发工具包 : Specifying KMS Key Id For EBS

windows - Powershell 远程处理 : Cannot connect to Windows 2012 EC2 Instance

ios - 当我更改约束的优先级时,更改不会使用 UpdateconstraintIfNeeded 进行动画处理