2015-11-22 34 views
0

我试图用解析对象的内容更新标签。这不起作用。带解析对象的Swift Update标签

if let userPoints = PFUser.currentUser()?["points"] as? String { 
     self.userPointsLabel.text = userPoints 
    } 

在这里,这工作虽然

if let pUserName = PFUser.currentUser()?["username"] as? String { 
     self.userNameLabel.text = "@" + pUserName 
    } 

的分列是用户类,所以我不明白为什么这是行不通的。

+0

是否分列包含字符串?你试图把它解析成一个字符串,如果不是它可能会失败,不是吗? – Moriya

+0

@Moriya我知道。这是一个数字。当我将它设置为Int时,我得到一个错误 – Niclas

+0

你会得到什么错误? – Moriya

回答

2

您正在尝试投射和诠释?字符串?并且失败,所以if语句永远不会是真的。

要分析的分值为int,然后用它作为一个字符串

if let userPoints = PFUser.currentUser()?["points"] as? Int { 
    self.userPointsLabel.text = "\(userPoints)" 
}