when you use a completion handler, do not use return.
func loadData(completion: @escaping (_ number: Int, _ strArr1: [String], _ strArr2: [String], _ strArr3: [String]) -> ()){ Alamofire.request(url!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { response in switch(response.result) { case .success(_): if let JSON = response.result.value as! [[String : AnyObject]]!{ //Here I retrieve the data } completion(number: numberRows, strArr1 : nameArray, strArr2 : ageArray, strArr3: birthdayArray) break case .failure(_): print("Error") completion(number: numberRows, strArr1 : nameArray, strArr2 : ageArray, strArr3: birthdayArray) break } } } loadData (completion: { (number, strArr1, strArr2, strArr3) in // do it // for exapmple self.number = number self.strArr1 = strArr1 // and so on })
or if you want to return some value in the closure, you should use the completion handler to return some value or something, for example, if you want to return a boolean:
func loadData(completion:(number: numberRows, strArr1 : nameArray, strArr2 : ageArray, strArr3: birthdayArray) -> (Bool))
and in loadData
loadData( completion: { ( number, strArr1, strArr2, strArr3 ) -> (Bool) in
or some think differently.
I use swift 3. but if you want another version to quickly pay attention to the names of external parameters and the names of internal parameters, for example: @escaping (_ number: Int, _ strArr1: [String], _ strArr2: [String], _ strArr3: [String]) -> ())
if you want to set the names of external parameters, you just need to remove _ and set a name for the parameters.