title: Checking if [NSObject : AnyObject]! is NSNull in Swift
body: <p>My project uses both Swift and Objective C. I have a singleton written in Objective C which as a property of the type NSDictionary.</p>
  
  <pre><code>@property(nonatomic, strong) NSDictionary *currentDictionary;
  </code></pre>
  
  <p>This is an old class that's being used throughout my project. I am trying to use this class in a Swift class like this</p>
  
  <pre><code>if let dict = DataManager.sharedManager().currentDictionary
  {
     // 
  }
  </code></pre>
  
  <p>The problem i am facing is that currentDictionary is being set using data from the server. At times this might be </p>
  
  <p>In Objective C classes, i can handle the situation with the following check</p>
  
  <pre><code>if ([currentDictionary isKindOfClass: [NSNull class]])
  {
     // Do nothing
  }
  </code></pre>
  
  <p>But i am not sure how to implement a similar check in Swift. I tried the following </p>
  
  <pre><code>if let data = DataManager.sharedManager().currentDictionary as? NSNull
  {
      return 
  }
  </code></pre>
  
  <p>But it doesn't work and also i get a compiler warning : </p>
  
  <p>"Cast from "[NSObject : AnyObject]!" to unrelated type "NSNull" always fails"</p>
  
  <p>This is different from checking for Null values within the dicitonary as they will be 'AnyObject's and i can try casting them into the type i want to check.</p>
  
  <p>Can someone please provide any pointers on how to handle this situation properly</p>