0
這是我用來填充我的collectionView單元格的NSObject類文件。我從firebase提取數據並使用它填充collectionViewCell。 Xcode給出了這個錯誤「在參數'字典'在調用失蹤參數」我盡我所能,但我無法找出缺少的東西。什麼導致這個錯誤,我該如何解決它?在調用中缺少參數'字典'的參數
class BusinessCategory: NSObject {
var ref: FIRDatabaseReference!
var name: String?
var logo: String?
var featurebusiness: [SampleBusinesses]?
var type: String?
init(dictionary: [String: Any]) {
self.name = dictionary["BusinessName"] as? String ?? ""
self.logo = dictionary["logo"] as? String ?? ""
}
static func sampleBusinessCategories() -> [BusinessCategory] {
var FinancialInstitutionCatergory = BusinessCategory()
FinancialInstitutionCatergory.name = "Financial Institutions"
var featurebusiness = [SampleBusinesses]()
//logic
FIRDatabase.database().reference().child("BusinessCategories/Banks").observeSingleEvent(of: .childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let financeApp = SampleBusinesses()
financeApp.setValuesForKeys(dictionary)
financeApp.name = dictionary["BusinessName"] as? String
featurebusiness.append(financeApp)
}
FinancialInstitutionCatergory.featurebusiness = featurebusiness
print(snapshot)
}, withCancel: nil)
return [FinancialInstitutionCatergory]
}
}
謝謝,你所說的那一行是錯誤的那一行。我添加了建議的更改,但它顯示此錯誤「無法將類型'[String:Any] .Type'(又名'字典 .Type')的值轉換爲期望的參數類型'[String:Any]'」 –
Ola
取出'< >'......那些不需要;它應該是'dictionary:[「foo」:「bar」]' –
那些不在代碼中的只是在註釋中。我把var變成了你發佈的 – Ola