1

I'm using RestKit to load objects from a specific web url. Doing the mapping and showing in a tableView. Ok, it works. But when I don't have internet connection, it loads the content of the last object loaded. The weird is:

It doesn't really loads the last object loaded. When I load the object "1", close the application, run it again to load the object "2", then close again, turn off the connection and run, it shows the object 1 content. Even if I clean the context load the object "2", then "1", turn off the connection and run, it shows again the object "1"content! It seems like the object "1" has some kind of "priority".

What I'm doing:

- (void)dataDownload
{
    [self showLoading:YES];
    RKObjectManager* objectManager = [RKObjectManager sharedManager];
    [objectManager loadObjectsAtResourcePath:@"my-url" delegate:self block:^(RKObjectLoader* loader) {
        loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Conteudo class]];
    }];

}

- (void) loadDatabase
{
    NSFetchRequest* request = [Conteudo fetchRequest];
    NSSortDescriptor* descriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:NO];
    [request setSortDescriptors:[NSArray arrayWithObject:descriptor]];
    self.conteudo = [Conteudo organizeData:[Conteudo objectsWithFetchRequest:request]];

}

`

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
        [self showLoading:NO];
        [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"LastUpdatedAt"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        NSArray *result = objects;
        if(result != nil){
            self.conteudo = [Conteudo organizeData:result];
            [[NSManagedObject managedObjectContext] save:nil];
        }
        else 
            [self loadDatabase];
        [self.tableView reloadData];
    }

`

Thanks for the help =]

4

0 回答 0