title: Problems with casting a Swift array of Structs to an NSArray and vice versa to use with NSUserDefaults
body: <p>I'm running into the problem of bridging Swift arrays of Structs to NSArrays. I want to store a Swift Array of Structs in NSUserDefaults. NSUserDefaults will only accept an NSArray. Can somebody tell me whether this is the correct way of doing it:</p>
  
  <p>First I declare an array some SwiftStruct and use it in my program: </p>
  
  <pre><code>var favorites = [SomeSwiftStruct]()
  </code></pre>
  
  <p>Then to store it I have to turn it into an NSArray. The only way to have the compiler not complain is to upcast it as follows:</p>
  
  <pre><code>let tempArray = favorites as Any as NSArray
  let defaults = NSUserDefaults.standardUserDefaults()
  defaults.setObject(tempArray, forKey: "favorites")
  </code></pre>
  
  <p>Then retrieving it I wanted to try this:</p>
  
  <pre><code>if let tempArray = defaults.objectForKey("favorites") as NSArray as Any as? [SomeSwiftStruct]{
    favorits = tempArray}
  </code></pre>
  
  <p>Unfortunately I can't yet test whether this works. For now I only know there are no compiler complaints</p>