Swift - Saving user data using NSKeyedArchiver, getting error on conversion to NSArray
<p>So I have an array of custom objects. When I try to save the array to NSUserDefaults, I have to archive them. Here is what I am doing to archive the array of my custom objects : </p>

<pre><code>override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {

    //3

    var allMessages = defaults.objectForKey(UserDefaultsMesssageKey) as! [AddMessageViewController.harassText]
    var aMessage = AddMessageViewController.harassText(phoneNumber: 0, message: "1", frequency: 1, active: 1)
    allMessages.append(aMessage)
    saveMessage(allMessages)


    return (allMessages.count)
}

func archiveMessage(message:[AddMessageViewController.harassText]) -&gt; NSData {
    let archivedObject = NSKeyedArchiver.archivedDataWithRootObject(message as NSArray)
    return archivedObject
}
func saveMessage(messages: [AddMessageViewController.harassText]) {
    let archivedObject = archiveMessage(messages)
    defaults.setObject(archivedObject, forKey: UserDefaultsMesssageKey)
    defaults.synchronize()
}
func retrieveData()-&gt; [AddMessageViewController.harassText]? {
    if let unarchiveObject = NSUserDefaults.standardUserDefaults().objectForKey(UserDefaultsMesssageKey) as? NSData {
        return NSKeyedUnarchiver.unarchiveObjectWithData(unarchiveObject) as? [AddMessageViewController.harassText]
    }
    return nil
}
</code></pre>

<p>The flow is : </p>

<ol>
<li><p>On saveMessage call, pass the custom array in to get archived. Here is what the array looks like to GDB. You can see that it is an array, and it has 1 class object contained in it. </p>

<p><code>([Harass_Your_Kate.AddMessageViewController.harassText]) $R0 = 1 value {
  [0] = 0x00007fa5ab409600 {
    ObjectiveC.NSObject = {
      isa = Harass_Your_Kate.AddMessageViewController.harassText
    }
    phoneNumber = 0
    message = "1"
    frequency = 1
    active = 1
  }
}</code></p></li>
<li><p>The array gets passed into archiveMessage. The code immediately fails on the NSKeyedArchiver method. The Error message is as follows :</p>

<pre><code>[_TtCC16Harass_Your_Kate24AddMessageViewController10harassText encodeWithCoder:]: unrecognized selector sent to instance 0x7fa5ab409600
</code></pre>

<p>2016-07-15 16:31:26.019 Harass Your Kate[5858:7847495] <strong>* -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.
2016-07-15 16:31:26.023 Harass Your Kate[5858:7847495] *</strong> Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtCC16Harass_Your_Kate24AddMessageViewController10harassText encodeWithCoder:]: unrecognized selector sent to instance 0x7fa5ab409600</p></li>
</ol>

<p>I appreciate all of the help, thank you in advance!</p>

<p>EDIT: Here is the definition of my object:</p>

<pre><code>class Text : NSObject {
    var phoneNumber = 0             //Text address to send to
    var message: String = ""        //Message to be sent
    var frequency = 24              //Number of hours between messages (usually a multiple of 24 - 24 = daily)
    var active = 0                  // 0 if cancelled, 1 if active

    init(phoneNumber: Int, message: String, frequency: Int, active: Int ){
        self.phoneNumber = phoneNumber
        self.message = message
        self.frequency = frequency
        self.active = active
    }
}
</code></pre>