title: Encode complex object swift 3.0
body: <p>I already read several posts and tried every solution, nothing works in my case. </p>
  
  <p>I am using this complex data structure and need to store array of DrawnObjects in file. But it crashing when it first came to encode a variable which itself is an array of Structure type. Any help ?</p>
  
  <p><strong>[_SwiftValue encodeWithCoder:]: unrecognized selector sent to instance 0x1702668c0</strong></p>
  
  <pre><code>enum ArchiverKeys : String
  {
      case imageView = "ImageView"
      case stateArray = "StateArray"
      case bezierPathArray = "BezierPathArray"
      case reactangleArray = "ReactangleArray"
      case deleted = "Deleted"
  }
     struct RectanglePath {
          var point1: CGPoint
          var point2: CGPoint
          var point3: CGPoint
          var point4: CGPoint
      }
  
      struct StateObject {
          var isAdd = true
          var path  = String()
      }
  
      class DrawObject: NSObject , NSCoding {
  
          var ImageView = UIImageView()
          var arrStates = [StateObject]()
          var arrBezierPaths = [UIBezierPath]()
          var rects = [RectanglePath]()
          var deleted = false
  
  
          override init() {
              ImageView = UIImageView()
              arrStates = []
              arrBezierPaths = []
              rects = []
              deleted = false
          }
  
          func encode(with archiver: NSCoder) {
              archiver.encode(self.ImageView, forKey:ArchiverKeys.imageView.rawValue )
              archiver.encode(self.arrStates, forKey: ArchiverKeys.stateArray.rawValue)
              archiver.encode(self.arrBezierPaths, forKey:ArchiverKeys.bezierPathArray.rawValue )
              archiver.encode(self.rects, forKey: ArchiverKeys.reactangleArray.rawValue)
              archiver.encode(self.deleted, forKey: ArchiverKeys.deleted.rawValue)
          }
  
          required convenience init(coder unarchiver: NSCoder) {
  
              self.init()
  
              self.ImageView      = unarchiver.decodeObject(forKey: ArchiverKeys.imageView.rawValue) as! UIImageView
              self.arrStates      = unarchiver.decodeObject(forKey: ArchiverKeys.stateArray.rawValue) as! [StateObject]
              self.arrBezierPaths = unarchiver.decodeObject(forKey: ArchiverKeys.bezierPathArray.rawValue) as! [UIBezierPath]
              self.rects          = unarchiver.decodeObject(forKey: ArchiverKeys.reactangleArray.rawValue) as! [RectanglePath]
              self.deleted        = (unarchiver.decodeObject(forKey: ArchiverKeys.deleted.rawValue) != nil)
          }
      }
  
      func saveArrayTo(_ directoryName: String , arrayToSave: NSArray) {
  
       //   let encodedData = NSKeyedArchiver.archivedData(withRootObject: arrayToSave)
        NSKeyedArchiver.archiveRootObject(arrayToSave, toFile: directoryName)
      }
  
       func loadArrayFrom(_ directoryName: String ) -&gt; NSArray? {
          let result = NSKeyedUnarchiver.unarchiveObject(withFile: directoryName)
          return result as? NSArray
      }
  </code></pre>