title: Define struct that is treated like a class in Swift
body: <p>In Swift a <code>String</code> structure is also treated as a class object like when using the <code>NSCoder</code> <code>encodeObject(_:forKey:)</code> method. I do know that <code>String</code> is directly bridged with the objective-c class, <code>NSString</code>, but is there a way to make a custom <code>struct</code> that behaves similarly? Perhaps bridge it to a custom class? I want to be able to do something like this:</p>
  
  <pre><code>struct SortedArray &lt;Value: Comparable&gt; {}
  
  // Would I need to create a bridge between 
  // SortedArray and NSSortedArray? Can I even do that?
  class NSSortedArray &lt;Value: Comparable&gt; : NSObject, NSCoding {
      required init?(coder aDecoder: NSCoder) {}
      func encodeWithCoder(aCoder: NSCoder) {}
  }
  
  class MyClass : NSObject, NSCoding {
      private var objects: SortedArray&lt;String&gt; = SortedArray&lt;String&gt;()
      required init?(coder aDecoder: NSCoder) {
          guard let objects = aDecoder.decodeObjectForKey("objects") as? SortedArray&lt;String&gt; else { return nil }
          self.objects = objects
      }
      func encodeWithCoder(aCoder: NSCoder) {
          aCoder.encodeObject(objects, forKey: "objects")
      }
  }
  </code></pre>