我正在使用 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()
}
最佳答案
这就是您访问 [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/