我正在使用sqlite文件从authorId获取diaryEntriesTeacher。当我打印变量authorId为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/