Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将AWS DynamoDB代码更新为Swift 3会导致错误_Swift_Amazon Web Services_Swift3_Amazon Dynamodb - Fatal编程技术网

将AWS DynamoDB代码更新为Swift 3会导致错误

将AWS DynamoDB代码更新为Swift 3会导致错误,swift,amazon-web-services,swift3,amazon-dynamodb,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.class

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 legacy编译器时,会发出警告“不推荐在Objective-C中使用字符串文字;请使用#选择器”

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

if (model.classForCoder.responds(to: #selector(AWSDynamoDBModeling.rangeKeyAttribute))) {
然而,我得到一个错误,说:

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


我一直在谷歌上疯狂地搜索,试图找出如何使这个Swift 3兼容,但没有运气。一些Swift 3专家将不胜感激

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

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