title: archive array of optional structs with NSCoding in Swift?
body: <p>I've done a lot of NSCoding archiving in Obj-C, but I'm not sure how it handles structs in Swift, nor arrays with optional values. Here is my code:</p>
  
  <pre><code>public struct SquareCoords {
      var x: Int, y: Int
  }
  </code></pre>
  
  <p>and here is the class which I need to store:</p>
  
  <pre><code>public class Player: NSCoding {
      var playerNum: Int
      var name = ""
      private var moveHistory: [SquareCoords?] = []
  
      init (playerNum: Int, name: String) {
          self.playerNum = playerNum
          self.name = name
      }
  
      public required init(coder aDecoder: NSCoder!) {
          playerNum = aDecoder.decodeIntegerForKey("playerNumKey")
          name = aDecoder.decodeObjectForKey("nameKey") as String
          moveHistory = aDecoder.decodeObjectForKey("moveHistoryKey") as [SquareCoords?]
      }
  
      public func encodeWithCoder(aCoder: NSCoder!) {
          aCoder.encodeInteger(playerNum, forKey: "playerNumKey")
          aCoder.encodeObject(name, forKey: "nameKey")
          aCoder.encodeObject(moveHistory, forKey: "moveHistoryKey")
      }
  ...
  </code></pre>
  
  <p>On the last line of the coder init, I get the following error message in XCode:</p>
  
  <pre><code>'AnyObject' is not convertible to [SquareCoords?]'
  </code></pre>
  
  <p>and on the last line of encodeWithEncoder:</p>
  
  <pre><code>Extra argument 'forKey' in call
  </code></pre>
  
  <p>Can anyone get me moving in the right direction?</p>