gpt4 book ai didi

ios - swift 3.0 如何在 Swift 3 中访问 `AnyHashable` 中的 `Any` 类型?

转载 作者:可可西里 更新时间:2023-11-01 05:42:56 24 4
gpt4 key购买 nike

我正在使用 sqlite 文件从 authorId 获取 diaryEntriesTeacher。当我打印变量 authorId is nil 时,它会生成以下 authorId 对象 代码:-

func applySelectQuery() {        
checkDataBaseFile()
objFMDB = FMDatabase(path: fullPathOfDB)
objFMDB.open()
objFMDB.beginTransaction()

do {
let results = try objFMDB.executeQuery("select * from diaryEntriesTeacher", values: nil)



while results.next() {
let totalCount = results.resultDictionary
let authorId = totalCount?["authorId"]!
print("authorId",authorId)
}


}
catch {
print(error.localizedDescription)
}
print(fullPathOfDB)
self.objFMDB.commit()
self.objFMDB.close()
}

输出 enter image description here

最佳答案

这就是您访问 [AnyHashable : Any] 字典的方式

var dict : Dictionary = Dictionary<AnyHashable,Any>()
dict["name"] = "sandeep"
let myName : String = dict["name"] as? String ?? ""

在你的情况下

let authorId = totalCount?["authorId"] as? String ?? ""

关于ios - swift 3.0 如何在 Swift 3 中访问 `AnyHashable` 中的 `Any` 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46294715/

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