swift 3.0如何在Swift 3中访问“ Any”中的“ AnyHashable”类型?

Jay*_*ngh 5 fmdb ios hashable swift3

我正在使用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()
}
Run Code Online (Sandbox Code Playgroud)

输出 在此处输入图片说明

San*_*ari 5

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

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

就你而言

let authorId = totalCount?["authorId"] as? String ?? ""
Run Code Online (Sandbox Code Playgroud)