title: ios swift, How to convert 'object to nsdata'
body: <p>I want to define a c ++ structure as swift code and serialize and deserialize it to write to socket.</p>
  
  <pre><code>class PacketHeader: NSObject, NSCoding {
      var ver: UInt8 = 0
      var len: UInt32 = 0
  
      required init(coder aDecoder: NSCoder) {
          ??
      }
  
      func encode(with aCoder: NSCoder) {
          ??
      }
  }
  </code></pre>
  
  <p>I can not find a function to decode and encode uint8, uint32.</p>