title: Could not cast value of type 'Swift.Optional<Swift.AnyObject>' (0x7f9d44715db0) to 'NSArray' (0x60000004f4f8)
body: <p>I'm trying to check <code>responseObject != nil</code> But It returns always true.</p>
  
  <p>I don't know <em>(How to check <code>nil</code> value for <code>ANY?</code>)</em></p>
  
  <p><strong>Here is my code</strong>:</p>
  
  <pre><code>success: { (operation: AFHTTPRequestOperation?,responseObject: Any?) in
                  print("view service reponse: \(String(describing: responseObject))")
                  print("view service reponse: \(responseObject!)")                
                  if responseObject != nil
                  {
                      let jsonObjects : NSArray = responseObject as! NSArray
                      print("All data1 : \(String(describing: jsonObjects))")
  
                      for dataDict : Any in jsonObjects {
  </code></pre>
  
  <p><strong>Crash Issue</strong> :</p>
  
  <p><a href="https://i.stack.imgur.com/dPbTY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPbTY.png" alt="enter image description here"></a></p>
  
  <p><strong>In Log Message:</strong></p>
  
  <blockquote>
    <p>view service reponse: Optional(nil)</p>
    
    <p>view service reponse: nil</p>
    
    <p>Could not cast value of type 'Swift.Optional' (0x7f9d44715db0) to 'NSArray' (0x60000004f4f8).
    (lldb) </p>
  </blockquote>
  
  <p>I tried below code also,</p>
  
  <pre><code>if let jsonOject = responseObject as? NSArray {
      // mean your responce is array type
  }
  else{
      // oterwise your responce in not array
  }
  </code></pre>
  
  <p>But still I got a crash...</p>