title: How to access a Dictionary passed via NSNotification, using Swift
body: <p>I have code that sends a notification (where serialNumber is a String):</p>
  
  <pre><code>  var dataDict = Dictionary&lt;String, String&gt;()
    dataDict["Identity"] = serialNumber
    dataDict["Direction"] = "Add"
              NSNotificationCenter.defaultCenter().postNotificationName("deviceActivity", object:self, userInfo:dataDict)
  </code></pre>
  
  <p>And code that receives this notification:</p>
  
  <pre><code>  func deviceActivity(notification: NSNotification) {
  
       // This method is invoked when the notification is sent
       // The problem is in how to access the Dictionary and pull out the entries
    }
  </code></pre>
  
  <p>I've tried a variety of code to accomplish this, with no success:  </p>
  
  <pre><code>let dict = notification.userInfo
  let dict: Dictionary&lt;String, String&gt; = notification.userInfo
  let dict: Dictionary = notification.userInfo as Dictionary
  </code></pre>
  
  <p>And while some of my attempts satisfy the compiler, none have yielded actual Strings when trying to access what has been extracted as a Dictionary:</p>
  
  <pre><code>let sn : String = dict["Identity"]!
  let sn : String = dict.valueForKey("Identity") as String
  let sn : String = dict.valueForKey("Identity")
  </code></pre>
  
  <p>So the question is this:  How do I write Swift code to extract an object, in this case a Dictionary, that was passed via a notification, and access the component parts of that object (in this case the keys and values)? </p>