1
I am in the following situation I have a request in the Alamofire that returns me a json that may or may not have data (usually has but may not). I want to treat when Response.result.value returns optional([]).
I tried that but it didn’t work
let json = response.result.value
print(json)//retorna Optional[]
if json == nil {
//aviso o usuario que nao tenho os dados pra mostrar
}
else{
//trabalho com os dados retornados
if let json = json {
for JSON in json {
//for para percorrer o objeto que me foi retornado
}
}
Only one thing, this 'json == nil' does not need, since down there you do if 'Let json = json'. if Let already checks if it is different from nil and takes the optional from it
– Lucas Eduardo
It doesn’t work because I’ll never have a nil because when there’s nothing in the json it gives me a []. Oh nil doesn’t work.
– João Vitor