swift 3.0 如何在 Swift 3 的 `Any` 中访问 `AnyHashable` 类型? [英] swift 3.0 How can I access `AnyHashable` types in `Any` in Swift 3?
本文介绍了swift 3.0 如何在 Swift 3 的 `Any` 中访问 `AnyHashable` 类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 sqlite 文件从 authorId 获取 diaryEntriesTeacher.当我打印变量 authorId 为 nil 时,它生成以下 authorId 对象代码:-
I'm using sqlite file to get the diaryEntriesTeacher from the authorId. it generates the following object of authorId when I print the variable authorId is nil Code :-
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()
}
输出
推荐答案
This is how you access Dictionary of [AnyHashable : Any]
This is how you access Dictionary of [AnyHashable : Any]
var dict : Dictionary = Dictionary<AnyHashable,Any>()
dict["name"] = "sandeep"
let myName : String = dict["name"] as? String ?? ""
就你而言
let authorId = totalCount?["authorId"] as? String ?? ""
这篇关于swift 3.0 如何在 Swift 3 的 `Any` 中访问 `AnyHashable` 类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文