Practicing writing a project using MVP. There is a task - to update the table after the new element has been added to the model.
Method inside DataStorageObserver that updates the model:
func addContact(contact: Contact) { DataStorage.sharedInstance.contactList.append(contact) NSNotificationCenter.defaultCenter().postNotificationName(Constants.Identifiers.sharedInstance.contactListUpdateIdentifier, object: nil) } View implements protocol methods
protocol ContactListViewProtocol: class { func updateData() } The update method itself, which is inside the View (the role of which is played by the UITableViewController)
func updateData() { self.tableView.reloadData() } Inside the presenter there is a method:
required init(view: ContactListViewProtocol) { self.view = view NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ContactListViewProtocol.updateData), name: Constants.Identifiers.sharedInstance.contactListUpdateIdentifier, object: nil) } Xcode suggests that the last required init contains an error
Argument of '#selector' refers to a method that is not subject to Objective-C
If you take a hint from Xcode, then it offers to substitute the @objc label to the method in the ContactListPresenterProtocol, which (method) does not relate to the update logic (I suppose that it is ide). How best to implement the update? Where should @objc be put down? Is it worth it?