ios - 迅速3类型“任何”错误

标签 ios firebase firebase-realtime-database swift3 xcode8

因此,我有一个使用swift 2的完美项目。然后更新了xcode,并将其转换为Swift3。现在,每次调用快照时,都会收到此错误。我正在使用Firebase作为后端。这是我的代码。

import Foundation
import Firebase
import FirebaseDatabase
import FirebaseAuth


struct User {

var username: String!
var email: String!
var photoUrl: String!
var country: String!
var ref: FIRDatabaseReference?
var key: String!


init(snapshot: FIRDataSnapshot){

    key = snapshot.key
    username = snapshot.value!["username"] as! String
    email = snapshot.value!["email"] as! String
    photoUrl = snapshot.value!["photoUrl"] as! String
    country = snapshot.value!["country"] as! String
    ref = snapshot.ref

}




}

我收到以下错误消息:类型“Any”没有下标成员。该错误位于其中包含snapshot.value的行上。有谁知道如何解决这个问题?

最佳答案

怎么样呢?

let values = snapshot.value as! Dictionary<String,String>
username = values["username"]
...

关于ios - 迅速3类型“任何”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39521764/

相关文章:

ios - 在提交到 Apple App Store 之前混淆 Swift 代码

ios - FIR 数据库查询 : how to do an inner join

android - 如何从 firebase 实时数据库修复 'Double data loading'

ios - 如何知道 CBPeripheral 何时不再可用

iphone - 使用 CABasicAnimation 对圆的结束角度进行动画处理

iphone - 如何将 void(摇动手势)放入 IBAction(按钮)中?

firebase - Firestore 子集合与数组

java - 尝试将图像保存到 firebase 存储时,android studio 出现错误

android - 无法将 Fabric 中的应用链接到现有的 Firebase 项目

java - 对 RecyclerView 的更改导致此错误 :E/RecyclerView: No adapter attached; skipping layout