0

The Swift 2.x code is as follows:

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
}

}

The line:

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

with the Swift legacy compiler gives the warning "Use of string literal for Objective-C is deprecated; use #selector"

It provides a fix it option, which changes it to:

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

However I then get an error saying:

Cannot call value of non-function type '((Selector) -> Bool)!'

I have been Googling like crazy trying to figure out how to make this Swift 3 compliant, but to no luck. Some Swift 3 expertise would be greatly appreciated!

SomeGuy
  • 3,725
  • 3
  • 19
  • 23

1 Answers1

0

You have to ensure your class derives from NSObject.

(Actually I am not sure, I found this answer in this link here)

Community
  • 1
  • 1
Alharbi
  • 1
  • 1