title: Completion handler and if statement within
body: <p>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 : </p>
  
  <pre><code>   class func login(username : String , password : String, _ completion: @escaping (Bool) -&gt; ()) {
          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 &gt; 0 {
                              print(user!.count)
                                                  completion(true)
                                                  }
                                              else {
                                                   print(user!.count)
                                                  completion(true)
                              }
                  }
              }
          }
  }
  </code></pre>
  
  <p>And I want to use it like this :</p>
  
  <pre><code>@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")
              }
          }
  
  }
  </code></pre>