title: How to fix 'unrecognized selector sent to instance' in Swift 4
body: <p>I'm trying to make a simple to-do list app using UserDefaults to store tasks. My program was working when I was using a string array to store, but as soon as I switched to storing my own objects, the issues started. The code might have some redundancy but I'm still learning how to store data locally on devices. </p>
  
  <p>I just need to know why this error is occurring and how I should go about fixing it.</p>
  
  <p>I've added spots in my code that I think the problem lies within, but I'm going to add all my code just in case it makes it clearer.</p>
  
  <p>SPOT 1: I added objc(ABCItems) here based on what the console told me.</p>
  
  <p>SPOT 2: I think there's an issue here because the code is failing around this point(The two print statements I have after never run).</p>
  
  <pre><code>import UIKit
  
  class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
  
  //SPOT 1
  
  @objc(ABCItems)class Items: NSCoder{
  
      var title : String!
      var completed : Bool!
  
      required init(coder decoder: NSCoder) {
          self.title = decoder.decodeObject(forKey: "title") as? String
          self.completed = decoder.decodeObject(forKey: "completed") as? Bool
      }
  
      init(title: String, completed: Bool) {
          self.title = title
          self.completed = completed
      }
  
      func encodeWithCoder(coder: NSCoder) {
          if let title = title { coder.encode(title, forKey: "title") }
          if let completed = completed { coder.encode(completed, forKey: "completed") }
      }
  }
  
  let defaults = UserDefaults.standard;
  var list = [Items]();
  @IBOutlet weak var tableList: UITableView!
  
  @IBAction func addItem(_ sender: Any) {
      let alert = UIAlertController(title: "Add an item", message: "", preferredStyle: .alert);
      alert.addTextField(configurationHandler: { (textField) in
          textField.placeholder = "Enter Task";
      })
      alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak alert] (_) in
          let textField = alert?.textFields![0];
          print("Text field: \(textField?.text ?? "")")
          if (textField?.text?.count)! &gt; 0 {
              let item = Items(title: (textField?.text)!, completed: true);
              self.list.append(item);
  
              //SPOT 2
  
              let itemData = try! NSKeyedArchiver.archivedData(withRootObject: self.list, requiringSecureCoding: false);
              print("PASS 1");
              self.defaults.set(itemData, forKey: "list");
              print("PASS 2");
              self.tableList.reloadData();
          }
      }))
      self.present(alert, animated: true, completion: nil);
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return list.count;
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "cell");
      cell.textLabel?.text = (list[indexPath.row] as AnyObject).title;
      cell.backgroundColor = UIColor (red: 0.18, green: 0.71, blue: 1.0, alpha: 1.0);
      return cell;
  }
  
  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
      if editingStyle == UITableViewCell.EditingStyle.delete {
          self.list.remove(at: indexPath.row);
          tableList.reloadData();
      }
  
  }
  override func viewDidLoad() {
      super.viewDidLoad()
      let itemDataRet = defaults.object(forKey: "list") as? NSData
  
      if let itemDataRet = itemDataRet {
          list = try! NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(itemDataRet as Data) as! [Items]
      }
  }
  }
  </code></pre>
  
  <p>This is the output I get:
  "-[ABCItems encodeWithCoder:]: unrecognized selector sent to instance 0x2829159e0"</p>