swift - 无法将类型 'Swift._NSContiguousString' 的值转换为“NSNumber”

标签 swift casting firebase nsstring nsnumber

if let userID = NSUserDefaults.standardUserDefaults().valueForKey("uid") as? String{

            currentUser = User(name: snapshot.value["name"] as! String ,phoneNumber: snapshot.value["phoneNumber"] as! String, userId: userID ,  isOnline: snapshot.value["isOnline"] as! Bool, key: "", lastName: snapshot.value["lastName"] as! String, photoUrl: "")

        }

我将 Firebase 用作 MBaaS,我在 currentUser 行收到此错误,奇怪的是,这并非一直发生,但只有在我离开应用程序(主页按钮)或重新进入应用程序时才会发生..
感谢您的宝贵时间。

最佳答案

试试这个(swift 3)

(userID as AnyObject).integerValue

关于swift - 无法将类型 'Swift._NSContiguousString' 的值转换为“NSNumber”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37165936/

相关文章:

ios - Uitableviewcell 具有自定义 View ,在应用程序运行时无法正确调整大小(下图)

c# - 基本类型转换 (c#)

java - 从 firebase 数据库 android 中查看特定类别中的图像的过程是什么

firebase - 尝试将文件上传到 firebase 云存储时,TypeError : appImpl. 存储不是函数

node.js - Bitbucket Pipeline + Firebase 托管

swift - iOS8 Swift TabBarController 更改图标颜色

java - 如何在 Swift 中将 Java 的 byte 改为 long

c++ - 如何在 C++ 中将 int 转换为枚举?

casting - TypeScript:要枚举的隐式数字

ios - 修改导航 Controller 中所有 ViewController 的高度