gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:44:05 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com