vendredi 29 mai 2015

How to convert predicates to SQL statement?

I am encountering a problem in my iOS app happening after 3 days of gathering data from server. I'm trying to pinpoint the problem and don't know if its a data corruption problem or a problem in the code.

I have downloaded the iOS database to my Mac and can run sql statements against it.

Is there a way to "convert" the following predicates to SQL statement so that I can verify the data?

    NSMutableArray *predicates = [[NSMutableArray alloc] init];
    NSDate *twoWeeksago = [[NSCalendar autoupdatingCurrentCalendar] dateByAddingUnit:NSCalendarUnitDay
                                                                           value:-14
                                                                          toDate:[NSDate date]
                                                                         options:0];
    [predicates addObject:[NSPredicate predicateWithFormat:@"isRemoved == 0"]];
    [predicates addObject:[NSPredicate predicateWithFormat:@"(publicationDatetime >= %@) AND (publicationDatetime <= %@)", twoWeeksago, [NSDate date]]];
    [predicates addObject:[NSPredicate predicateWithFormat:@"(source == %@) OR (source == %@)", @"BBC", @"Guardian"]];
    NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];

Aucun commentaire:

Enregistrer un commentaire