I'm working on a way to know if data has been downloaded and recorded correctly on Core Data. Due to the poor quality of 3G connections and the potential for failure, I would like to know if there is a way to query the core data and see if there is any way to return the empty records in an array.
The initial idea I had is to get the records in the entities and scan them for fields with NULL values. And then create a request to populate the data correctly.
But I would like to know if Core Data has a method or function that does this, returning an array with the failed records.
Example Entity with fields filled in failed:
ID | NOME | VALOR | IMAGEM
-------------------------------
0 | arroz | NULL | skms.png
-------------------------------
1 | feijao| NULL | ksle.png
-------------------------------
2 | carne | 5,00 | NULL
-------------------------------
3 | uva | 6,00 | NULL
-------------------------------
4 | pera | 7,00 | lskx.png
-------------------------------
5 | NULL | NULL | NULL
-------------------------------
// Codigo usado para Download
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
[operationManager.requestSerializer setValue:urlGlobalToken forHTTPHeaderField:urlGlobalHttpHeader];
[operationManager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableArray* arrayDataReceived = [responseObject objectForKey:@"data"];
cleanArray = [[NSMutableArray alloc]init];
arrayURLImagens = [[NSMutableArray alloc]init];
for ( NSMutableDictionary* valuesDict in arrayDataReceived) {
// Este modelo é somente para exemplo.
// This model is only for example.
NSMutableDictionary* cleanDict = [[NSMutableDictionary alloc]init];
[cleanDict setObject: [valuesDict objectForKey:@"id"] forKey:@"id"];
[cleanDict setObject: [valuesDict objectForKey:@"nome"] forKey:@"nome"];
[cleanDict setObject: [valuesDict objectForKey:@"data"] forKey:@"data"];
[cleanDict setObject: [valuesDict objectForKey:@"descricao"] forKey:@"descricao"];
[cleanDict setObject: [valuesDict objectForKey:@"updated_at"] forKey:@"updateat"];
// Imagens para update
[cleanDict setObject: [valuesDict objectForKey:@"imagem"]forKey:@"urlimagem"];
// Armazena os dicionarios em um Array
[cleanArray addObject:cleanDict];
}
_dadosBrutosRecebidos = [[NSMutableDictionary alloc]init];
[_dadosBrutosRecebidos setObject:arrayURLImagens forKey:@"urlimagem"];
[_dadosBrutosRecebidos setObject:cleanArray forKey:@"strings"];
[self.delegate performSelector:@selector(downloadDadosEventosCompleto)];
app.networkActivityIndicatorVisible = NO;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
app.networkActivityIndicatorVisible = NO;
NSLog(@"failure. Error:%@. URL ERRO: %@",error, url);
}];
}