我在swift 2中有这个代码,可以从Parse中获取Int phone no并显示在文本框中

        if (PFUser.currentUser()!["phoneNumber"] !== nil)
    {
        mobile.text = String(PFUser.currentUser()!["phoneNumber"] as? Int)
    }

但它显示为Optional(XXXXXXXXXX)…但我只希望它没有可选的包装,如XXXXXXXXXX

最佳答案

解决方案是使用可选链接和可选绑定

if let phoneNumber = PFUser.currentUser()?["phoneNumber"] as? Int {
    mobile.text = String(phoneNumber)
}

关于swift - 在文本框中快速显示Int值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33453701/

10-13 01:12