Search code examples
swiftdictionaryfirebasefirebase-realtime-databasensobject

Missing argument for parameter 'dictionary' in call


This is my NSObject class file that I am using to populate my collectionView cell. I am fetching my data from firebase and populating the collectionViewCell with it. Xcode is giving this error "Missing argument for parameter 'dictionary' in call" I have tried all I can but I could not figure out what is missing. What is causing this error and how can I fix it?

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]

}
}

Solution

  • The error is stating you need to include the dictionary parameter in whatever line has the error; an example might look something like this:

    var FinancialInstitutionCatergory = BusinessCategory(dictionary: [String : Any])
    

    It's unclear which line in your code has the error; you'll need to include the parameter somewhere.