title: How to assign a Dictionary to AnyObject in swift
body: <p>I have been playing around with Swift. I have had multiple errors with types, especially working with Swift and my old Objective-C classes. The problem with this method is: I am expecting an array made of NSDictionarys in Objective-C.</p>
  
  <pre><code>var curArr:[Dictionary&lt;String, AnyObject&gt;] = self.getItemsForCurrentStack()
  var arrToReturn:[(Dictionary&lt;String, AnyObject?&gt;)] = []
  for obj in curArr{
      arrToReturn.append(["image": UIImage(named: obj["imageName"] as! String), "color": UIColor(red:obj["colorDic"]!["red"] as! CGFloat, green:obj["colorDic"]!["green"] as! CGFloat, blue:obj["colorDic"]!["blue"] as! CGFloat, alpha:1.0), "percentage": obj["percantage"]])
  }
  return arrToReturn
  </code></pre>
  
  <p>This returns Dictionaries (which are NSDictionaries) in Swift. But the last line throws me an error:</p>
  
  <blockquote>
    <p>Dictionary' is not identical to 'AnyObject'</p>
  </blockquote>
  
  <p>I've tried using <code>as! [AnyObject]</code></p>
  
  <p>But that throws another error:</p>
  
  <blockquote>
    <p>'AnyObject' is not a subtype of 'Dictionary'</p>
  </blockquote>
  
  <p>I don't get the second error, since this doesn't have to be a subtype, but the other way around. Any ideas on how to solve this? I didn't find an answer for several hours of googleing and researching.</p>