簡體   English   中英

uint 不能轉換為 int

[英]uint not convertible to int

我只想打印孩子數並將其設置為標簽。

這是我的 JSON 結構:

  • 簡單登錄2

    • 姓名
    • 年齡
    • 郵政
      • 帖子1:“asdasd”
      • 帖子2:“薩達斯”
      • 帖子3:“asdasd”

我想打印帖子中的兒童數量或將其設置為標簽我應該怎么做?

我試過這個:

ref.childByAppendingPath("users").childByAppendingPath(ref.authData.uid).childByAppendingPath("post").observeSingleEventOfType(.Value, withBlock: { snapshot in

    self.postCount = snapshot.childrenCount.value
    println(self.postCount)

})'

但它說 word 不能轉換為 uint。

更新 :

這就是我創建用戶的方式:

  var userId = authData.uid

                        let newUser = [
                            "Provider" : authData.provider,
                            "email"    : authData.providerData["email"] as? NSString as? String,
                            "name"     : self.Name.text,
                            "Image"    : "",
                            "location" : "",
                            "about"    : "",
                            "age"      : "",
                        ]


self.ref.childByAppendingPath("users").childByAppendingPath(authData.uid).setValue(newUser)

這就是我向每個用戶添加子“帖子”的方式!

(在按鈕內我做了這個編碼)

ref.childByAppendingPath("users/\(ref.authData.uid)/post").childByAutoId().setValue(text.text)

根據 Firebase 文檔,childrenCount 是一個 NSUInteger。

@property (readonly, nonatomic) NSUInteger childrenCount

我會放棄 .value 調用,因為它不需要。 您還可以使用字符串插值將值轉換為字符串。

ref.childByAppendingPath("users").childByAppendingPath(ref.authData.uid).childByAppendingPath("post").observeSingleEventOfType(.Value, withBlock: { snapshot in

    self.postCount = snapshot.childrenCount
    println("\(self.postCount)")
})

如果您有一個 UILabel 想要將 postCount 設置為文本,請執行以下操作。 請注意,例如我的 UILabel 被稱為標簽。

label?.text = "\(self.postCount)"

注意標簽上的問號。 由於文本是一個可選屬性,我們使用可選鏈來設置值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM