I've been trying to resolve this "EXTRA ARGUMENT 'title' IN CALL" ALL week. Below is the code with the error I'm having trouble with. I've added the new code that I'm currently working with in Xcode. The error I'm getting with this code is:
"ARGUMENT PASSED TO CALL THAT TAKES NO ARGUMENTS"
NEW CODE
import UIKit import Firebase import FirebaseDatabase struct PostStruct { struct PostStruct { let title: String let message : String } } class DatabaseViewController: UITableViewController { var posts: [PostStruct] = [] override func viewDidLoad() { super.viewDidLoad() // let databaseRef = Database.database().reference() databaseRef.child("Posts").queryOrderedByKey().observe(.childAdded, with: { snapshot in let snapshotValue = snapshot.value as? NSDictionary let title = snapshotValue?["title"] as? String let message = snapshotValue?["message"] as? String self.posts.insert(PostStruct(title: title ?? "", message: message ?? ""), at: 0) **// <-- ARGUMENT PASSED TO CALL THAT TAKES NO ARGUMENTS** self.tableView.reloadData() }) post() } func post(){ let title = "Title" let message = "Message" let post : [String : AnyObject] = ["title" : title as AnyObject, "message" : message as AnyObject] let databaseRef = Database.database().reference() databaseRef.child("Posts").childByAutoId().setValue(post) } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return posts.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCell(withIdentifier: "cell") if cell == nil { cell = UITableViewCell(style: .default, reuseIdentifier: "cell") cell?.textLabel?.text = "New value" cell?.detailTextLabel?.text = "New value" return cell! } else { cell?.textLabel?.text = "" //reset value cell?.detailTextLabel?.text = "" // resetValue cell?.textLabel?.text = "New value" cell?.detailTextLabel?.text = "New value" return cell! } } } OLD CODE
import UIKit import Firebase import FirebaseDatabase struct PostStruct { let title = String!.self let message : String! } class DatabaseViewController: UITableViewController { var posts = [postStruct]() override func viewDidLoad() { super.viewDidLoad() // let databaseRef = Database.database().reference() databaseRef.child("Posts").queryOrderedByKey().observe(.childAdded, with: { snapshot in let snapshotValue = snapshot.value as? NSDictionary let title = snapshotValue?["title"] as? String let message = snapshotValue?["message"] as? String self.posts.insert(PostStruct(title: title ,message: message), at: 0) // **<-- EXTRA ARGUMENT 'title' IN CALL** self.tableView.reloadData() }) post() } func post(){
postStructis actually a Struct like its name implies, you should capitalize it asPostStruct; that's a Swift convention, so following it makes things clearer for everyone. DoesPostStructhave aninitthat takes both atitleand amessage?