var serviceTypeName = [String]()
override func viewDidLoad() {
super.viewDidLoad()
getServiceType()
debugPrint(serviceTypeName)
}
I try to get an array of names from web API, and store it into the array serviceTypeName. Below is my function of get service name (I used Alamorfire lib)
func getServiceType() {
Alamofire.request(...
.responseJSON { response in
switch response.result {
case .success:
if let responseValue = response.result.value {
var serviceName: [String] = []
let json = JSON(responseValue)
for (key, subJson):(String, JSON) in json["results"] {
if let name = subJson["name"].string {
serviceName.insert(name, at: Int(key)!)
}
}
self.serviceTypeName = serviceName
} ...
However, I got null array [] after this function, just like the function didn't do anything. I make sure that I got correct data from server and put into serviceName correctly every loop. But I cannot set it to the serviceTypeName. Would you please point out the mistakes?