So I am working on a simple Core Data app that can track how much I have made from various apps I sell (right now I just have two iPhone ones I charge for). This is also the app that my Expenses tutorial is based on. I am working on the monthly totals portion again and trying to use fetching for the totals. I have added a 'month' derived attribute to the AppSales entity (yes, I know it should be singular, but I dare not change it now). I have added a text field to the interface that shows the month attribute correctly with bindings. However, when I am in the Application entity's class and do a fetch for all AppSales that have an application of self and a month of x (varies by method, 1-12) I get a keypath not found in entity message in the log. I have tested to make sure that I can in fact fetch AppSales entities based on the Application instance and that part works, I can even NSLog the month of the first item in the array. I must be missing something really simple but have no idea what it is. I have listed relevant code below:

From Application.m:

- (NSNumber *)janTotal
{
        NSLog(@"Application %@: janTotal starting...", self.title);
        float total = 0.0;
        // create a fetch request and set it's entity
        NSFetchRequest *janRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AppSales" inManagedObjectContext:[self managedObjectContext]];
        [janRequest setEntity:entity];
        
        // build the predicate and set it
NSPredicate *selfPredicate = [NSPredicate predicateWithFormat:@"application = %@", self]; NSPredicate *monthPredicate = [NSPredicate predicateWithFormat:@"month = %i", 1]; NSPredicate *comboPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:selfPredicate, monthPredicate, nil]];
        [janRequest setPredicate:comboPredicate];
        
        NSLog(@"Application %@: janTotal predicates set.", self.title);
        
        NSFetchRequest *otherRequest = [[NSFetchRequest alloc] init];
        [otherRequest setEntity:entity];
        [otherRequest setPredicate:selfPredicate];
        NSError *otherError = nil;
NSArray *anotherArray = [[self managedObjectContext] executeFetchRequest:otherRequest error:&otherError];
        NSLog(@"anotherArray count = %i", [anotherArray count]);
NSLog(@"anotherArray firstObject month = %@",[[anotherArray objectAtIndex:1] month]);
        
        NSError *anError = nil;
NSArray *anArray = [[self managedObjectContext] executeFetchRequest:janRequest error:&anError];
        
NSLog(@"Application %@: janTotal [anArray count] = %i", self.title, [anArray count]);
        
        // check to see if we got anything
        if (anError != nil)
        {
                NSLog (@"fetch error = %@", anError);
        }
        if ([anArray count] != 0)
        {
                AppSales *value;
                NSEnumerator *e = [anArray objectEnumerator];
                while (value = [e nextObject])
                {
                        total = total + [value.total floatValue];
                }
        }
                
        [janRequest release];
                
        return [NSNumber numberWithFloat:total];
}

Here is the console output:
2009-09-17 12:44:17.659 myAppSales[11094:a0f] Application DMXRef: janTotal starting... 2009-09-17 12:44:17.660 myAppSales[11094:a0f] Application DMXRef: janTotal predicates set.
2009-09-17 12:44:17.662 myAppSales[11094:a0f] anotherArray count = 117
2009-09-17 12:44:17.663 myAppSales[11094:a0f] anotherArray firstObject month = 5 2009-09-17 12:44:17.663 myAppSales[11094:a0f] keypath month not found in entity <NSSQLEntity AppSales id=2>

Any ideas would be greatly appreciated.

Thanks,
Mike Swan
http://www.michaelsswan.com

"Change itself is not painful it is resistance to change that causes pain."



_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to