ios - 类型[字符串: String] does not conform to protocol 'AnyObject'

标签 ios json swift nsstring firebase

我正在尝试在 JSON 结构中创建一个名为 USERSLIST 的新路径!它将包含在我的 firebase 应用程序中创建帐户的用户列表。在我的 JSON 中,它必须如下所示:

USERSLIST:

  • simpleLogin6 : aa@gmail.com
  • simpleLogin9 : bb@gmail.com

它应该将创建的帐户的 uid 作为键,将电子邮件作为值。

我写了这段代码:

var usersList = [self.ref.authData.uid : authData.providerData["email"] as? NSString as? String,]
self.ref.childByAppendingPath("userList").childByAutoId().setValue(usersList)

但它在 setValue 行代码中显示了一个错误:

type [String: String] does not conform to protocol 'AnyObject'

最佳答案

var userList  = [String:String]()
if let strEmail = authData.providerData["email"] {

    usersList[self.ref.authData.uid] = strEmail as! String

}

关于ios - 类型[字符串: String] does not conform to protocol 'AnyObject' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32476448/

相关文章:

ios - NumberFormatter 字符串(来自 :NSNumber) method has issues with decimal places

ios - 从用户输入的 UITextField 创建没有硬编码范围的 NSAttributedString

ios - 滚动 UITableView 时 UITableViewCell 位置发生变化

ios - UISegmentedControl 在 UITableView 标题上的行为方式很奇怪

iphone - XCode:从plist读取数据到NSmutablearray

jquery - 带有多个选择的 web.py Json

c# - 从 JSON 检索项目时获取 'Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken'

android - 为什么它只显示来自 json 数组的最新数据

ios - 如何快速打印数组中对象的值,而不是它的位置

ios - 如何通过单击 WKWebView 中的按钮打开社交链接