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))) {
然而,我得到一个错误说:
无法调用非功能类型的值'((选择器) - > Bool)!'
我一直在谷歌搜索疯狂试图弄清楚如何使这个Swift 3兼容,但没有运气。一些Swift 3的专业知识将不胜感激!