Q:

Completion handler and if statement within

I wrote a function that I guess it should return a boolean , I'm using completion handler and switch and if statements within 
this is my code : 
   class func login(username : String , password : String, _ completion: @escaping (Bool) -> ()) {
        let url = "http://127.0.0.1:3000/login/"+username+"/"+password
        Alamofire.request(url).responseJSON{response in
            switch response.result
            {
            case .failure:
                print(response)
                completion(false)
            case .success:
                    if let dict = response.value as?  NSDictionary {
                          let dict = response.value as?  NSDictionary
                        let user = dict!["users"] as?  NSArray
                        if user!.count > 0 {
                            print(user!.count)
                                                completion(true)
                                                }
                                            else {
                                                 print(user!.count)
                                                completion(true)
                            }
                }
            }
        }
}

And I want to use it like this :
@IBAction func LoginBtn(_ sender: Any) {
        API.login(username: textUsername.text!,  password: textPassword.text!) { 
            success in
            if success{
                // if the function return true print(hello)
                //else print (type again)
            print("Welcome")
            }
            else{
                print("NO")
            }
        }

}

A:

First of all don't use NSArray and NSDictionary in Swift, use native types. 
Second of all never use .count > 0 to check for empty array or empty string.  There is an optimized property isEmpty

Your code is very cumbersome and there are a few redundant parts in it.  
The logic is to return true if the users array is valid and not empty otherwise return false. 
So the success branch can be reduced to
case .success:                
  if let dict = response.value as? [ String:Any], let users = dict!["users"] as? [[ String:Any]], ! users.isEmpty { 
      completion(true)
  } else { 
      completion(false)                  
  }

