Question

I have this fetch request

-(NSArray*)getMeasureDaysForMeasures:(NSArray*)measures startingFromDate:(NSDate*)startingDate{
    if(measures){
        NSFetchRequest* measureRequest=[NSFetchRequest fetchRequestWithEntityName:@"MeasureDay"];
        measureRequest.sortDescriptors=nil;
        NSPredicate* finalPredicate=nil;
        NSArray* orPredicates=[[NSArray alloc]init];
        for(NSString* entity in measures){
            NSString* lowerCaseEntity=[entity lowercaseString];
            NSPredicate* newPredicate=[NSPredicate predicateWithFormat:@"%@ != %@",lowerCaseEntity,nil];
            orPredicates=[orPredicates arrayByAddingObject:newPredicate];
        }
        finalPredicate=[NSCompoundPredicate orPredicateWithSubpredicates:orPredicates];
        NSLog(@"PREDICATE IS : %@",finalPredicate);
        if(startingDate){
            NSPredicate* datePredicate=[NSPredicate predicateWithFormat:@"date >= %@",startingDate];
            finalPredicate=[NSCompoundPredicate andPredicateWithSubpredicates:@[datePredicate,finalPredicate]];
        }
        measureRequest.predicate=finalPredicate;
        AppDelegate* appDelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
        return [appDelegate.documentManagedObjectContext executeFetchRequest:measureRequest error:nil];
    }
    return nil;
}

So it should not return any MeasureDay objects with weight==null But this NSLog shows that it doest return those objects, and treats their value as < fault >.

for(MeasureDay* day in [self getMeasureDaysForMeasures:_arrayOfChosenMeasures startingFromDate:nil]){
    NSLog(@"%@",day.weight);
}

returns

2014-01-01 19:36:57.682  PREDICATE IS : "weight" != nil
2014-01-01 19:36:57.686  <Weight: 0x14e6f6e0> (entity: Weight; id: 0x14eb0320 <x-coredata://09796286-39C5-4F4B-B7E8-81FD47B256D8/Weight/p1> ; data: <fault>)
2014-01-01 19:36:57.688  <Weight: 0x14d69ef0> (entity: Weight; id: 0x14d79c70 <x-coredata://09796286-39C5-4F4B-B7E8-81FD47B256D8/Weight/p5> ; data: <fault>)
2014-01-01 19:36:57.689  (null)
2014-01-01 19:36:57.691  (null)
2014-01-01 19:36:57.692  (null)

What am i doing wrong?

Was it helpful?

Solution

figured it out. Should've used this code:

 NSPredicate* newPredicate=[NSPredicate predicateWithFormat:@"%K != %@",lowerCaseEntity,nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top