【问题标题】:type [String: String] does not conform to protocol 'AnyObject'类型 [String: String] 不符合协议 'AnyObject'
【发布时间】:2015-09-09 09:56:25
【问题描述】:

我正在尝试在我的 JSON 结构中创建一个名为 USERSLIST 的新路径!它将包含在我的 firebase 应用程序中创建帐户的用户列表。在我的 JSON 中,它必须看起来像这样:

用户列表:

  • 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'

【问题讨论】:

  • authData的类型是什么?您能否向我们展示更多代码以了解所有变量?

标签: ios json swift nsstring firebase


【解决方案1】:
var userList  = [String:String]()
if let strEmail = authData.providerData["email"] {

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

}

【讨论】:

  • 在您的代码中进行一些更改,userList 正在更新,代码正在运行,但问题是每次任何其他用户登录 uid 和电子邮件都被替换而不添加.. 我希望结构保存创建的用户列表..
  • 它不应该替换创建的孩子,而是在创建帐户时将更多的孩子添加到列表中@chetan prajapati
  • 这就是我创建用户列表的代码! var userList:[字符串:字符串]? if let strEmail: AnyObject = authData.providerData["email"] { userList = [self.ref.authData.uid : strEmail as String] } self.ref.childByAppendingPath("userList").setValue(userList) @chetan prajapati
  • 每次 key(self.ref.authData.uid) 不同?或所有电子邮件地址都相同
  • 是的,因为新用户通过 childByautoID @chetan Prajapati 创建帐户,所有电子邮件地址都不同
猜你喜欢
  • 2014-11-17
  • 2014-10-23
  • 2015-01-02
  • 2016-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多