• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Doing a NSFetchRequest on a single NSManagedObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Doing a NSFetchRequest on a single NSManagedObject


  • Subject: Doing a NSFetchRequest on a single NSManagedObject
  • From: Andrew Sage <email@hidden>
  • Date: Sat, 6 Aug 2005 09:51:30 +0100

My data model consists of an Entity called Project which has a one to many relationship to
an Entity called Task. Task has an attribute called completedDate.


I am wanting to get the number of Tasks that do not have a completedDate set.

Project is represented by a class called Project.

I have created the following method in Project:

-(int)tasksCount
{
    int total = 0;

NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task"
inManagedObjectContext:moc];


NSPredicate * predicate;
predicate = [NSPredicate predicateWithFormat:@"completedDate = NIL"];


    NSFetchRequest * fetch = [[NSFetchRequest alloc] init];
    [fetch setEntity: entity];
    [fetch setPredicate: predicate];

    NSArray * results = [moc executeFetchRequest:fetch error:nil];
    [fetch release];

    total = [results count];

    return total;
}


However, this returns the number of Tasks that do not have a completedDate set for all the Projects
and not just the current one.


Thanks.
Andrew
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Logout question
  • Next by Date: Doing a NSFetchRequest on a single NSManagedObject
  • Previous by thread: Logout question
  • Next by thread: Doing a NSFetchRequest on a single NSManagedObject
  • Index(es):
    • Date
    • Thread