Question

Frankly, I'm a little embarrassed to even ask this question for the perceived absurdity and without being able to personally reproduce it, but...

In my iOS 7 application, I've received many complaints from users that certain portions of the app "don't work." By "don't work," they mean that a UITableView being populated by a NSFetchRequestDelegate's methods has zero rows. The only thing in common about the error reports are the specific NSFetchRequests that return zero objects and the physical location of the users. The users are all in Nordic countries (Norway, Sweeden, Finland, etc.). This could be a coincidence, or just that the Nordic are more vocal when there is a bug, but this bug makes me nervous.

I've tried setting my phone to use Nynorsk as the default language and using Nordic international units (which my app does happily support with NSDateFormatter and friends). The app works fine for me when I do this, but I am physically in the USA. I've even gone so far as to use a user account with my app whose server-side data was generated in Finland (all sorts of diacritics in strings that will be saved with CoreData), and it still works as expected.

I don't see anything abnormal with my instantiation of my NSFetchedResultsController, but for completeness, here is one that returns no results:

- (NSFetchedResultsController *)fetchedResultsController
{
    if (_fetchedResultsController != nil)
        return (_fetchedResultsController);

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:kTTAEntityCheckinDetail inManagedObjectContext:MOC];
    [fetchRequest setEntity:entity];
    [fetchRequest setFetchBatchSize:kTTACheckinDetailBatchSize];

    NSSortDescriptor *checkinIDSort = [NSSortDescriptor sortDescriptorWithKey:kTTACheckinDetailAttributeCheckinID ascending:NO];
    [fetchRequest setSortDescriptors:@[checkinIDSort]];

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:MOC sectionNameKeyPath:@"sectionIdentifier" cacheName:nil];
    _fetchedResultsController = aFetchedResultsController;

    NSError *error = nil;
    if ([self.fetchedResultsController performFetch:&error] == NO)
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

    return (_fetchedResultsController);
}

It's possible that performFetch is failing, but I do not have access to the user's logs. Perhaps I should detect the user's location and log this to a remote server?


Solution: CoreData failed to save the objects because a date field was nil. This field wasn't populated because the locale of a NSDateFormatter was not set. See the comments of @flexaddicted's accepted solution for details.

Was it helpful?

Solution

This could be a shot in the dark.

First, what type of objects do you retrieve? Based on dates?

Then, Yes, I would log both locally and server-side. To log locally you could ask users in Nordic Countries to send a feedback (based on email) with Core Data store or just file logs (the logs will be inserted in the right points). The latter could be achieved by CocoaLumberjack.

An example of this can be found at CocoaLumberjack and Mailing logs by NSScreencast.

TestFlight could be an alternative way but I guess you are in production.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top