0
我想用三個條件來篩選火力地堡查詢結果:無法轉換int類型的值與預期的參數類型布爾
let posts = snapshot.childSnapshots.map {
Post(snapshot: $0)
}.reversed().filter {
post?.isGlobal == dataFilter && (self.dependents.contains($0.postedBy) || self.currentUser?.uid == $0.postedBy)
}
第一個條件(post.isglobal == datafilter)
必須得到滿足。然後,我想在滿足其餘兩個條件中的任何一個時進一步過濾帖子。
上面的代碼返回一個錯誤:Binary operator == cannot be applied to operands of type NSNumber? and Int
任何幫助,將不勝感激。 謝謝!
編輯:dataFilter
變量定義爲視圖控制器類中的一個全局變量:
var dataFilter = 0
比較與'做'==,而不是與'=' –
如果我將其更改爲'==',我會收到錯誤'Binary operator ==不能應用於NSNumber類型的操作數?和Int' – winston
嘗試'(post?.isGlobal.intValue ?? 0)=='或者在訪問它的isGlobal intValue屬性之前打開你的可選文章 –