2015-11-22 31 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)" 
}