将AWS DynamoDB代码更新为Swift 3会导致错误
Swift 2.x代码如下:将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
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 (实际上我不确定,我在这个链接中找到了这个答案 )