Reputation: 467
I am trying to append two values to my variable countryAndCode
.
I get the error: Extra argument 'code' in call
which does not make any sence to me because countryAndCode
is taking two values: Country and Code??
What have I done wrong?
Here is my code:
func startObersvingDB() {
FIRDatabase.database().reference().child("UserInformation").observeEventType(.ChildAdded, withBlock: { snapshot in
if let title = snapshot.value!["usersUID"] as? String {
self.tableData.append(title)
if let name = snapshot.value!["userName"] as! String? {
self.tableDataNames.append(name)
for i in 0...self.tableData.count {
var countryAndCode: [(country:String, code: String)]
countryAndCode.append(self.tableData[i], code: self.tableDataNames[i])
}
self.tableView.reloadData()
} else {
print("Noget virker ikke i startObservingDB")
}
}
})
}
If it is relevant; I am trying to create a search bar that is showing the name of the user, while showing their picture also (which is why I need the id in tableData).
Upvotes: 0
Views: 379
Reputation: 761
You simply need to encapsulate the arguments you are passing in, in brackets.
Change this:
countryAndCode.append(self.tableData[i], code: self.tableDataNames[i])
to:
countryAndCode.append((self.tableData[i], code: self.tableDataNames[i]))
The reason you need to this is because you are declaring your array with [(country:String, code: String)]
with the brackets encapsulating the arguments inside the array, so you need to do the same when appending data to it.
Upvotes: 1