I'm having a difficult time trying not to write nested loops whenever I avoid force downcasting and unwrapping optionals. Is there a way to do this?
Example:
var customers = [Customer]()
if response.result.isSuccess, let jsonDictionary = response.result.value as? NSDictionary {
if let usersJSON = jsonDictionary.object(forKey: "users") as? [NSDictionary] {
for customerJSON in usersJSON {
if let customer = Customer.from(customerJSON) {
customers.append(customer)
}
}
}
}
completionHandler(customers)