• 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
Re: Removing an Object with A Certain Title from an NSTreeController.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing an Object with A Certain Title from an NSTreeController.


  • Subject: Re: Removing an Object with A Certain Title from an NSTreeController.
  • From: Joshua Garnham <email@hidden>
  • Date: Sat, 10 Oct 2009 05:28:50 -0700 (PDT)

Ok, I'll post the actual code that I am using and is giving the problem.

Here it is:

    for(NSString *title in oldTasks) {
        // Get the moc and prepare a fetch request for the required entity
        NSManagedObjectContext *moc = [self managedObjectContext];
        NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"projects" inManagedObjectContext:moc];
        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        [request setEntity:entityDescription];

        // Create a predicate for an array of names.
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title IN %d", oldTasks];
        [request setPredicate:predicate];

        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
        [request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

        // Execute the fetch request put the results into array
        NSError *error = nil;
        NSArray *resultArray = [moc executeFetchRequest:request error:&error];
        if (resultArray == nil)
        {
            // Diagnostic error handling
            NSAlert *anAlert = [NSAlert alertWithError:error];
            [anAlert runModal];
        }

        JGManagedObject *objectToDelete = [resultArray objectAtIndex:0];
        // Delete the object.
        [moc deleteObject:objectToDelete];
}


-----
Josh


________________________________
From: Abizern <email@hidden>
To: Joshua Garnham <email@hidden>
Sent: Saturday, 10 October, 2009 13:04:06
Subject: Re: Removing an Object with A Certain Title from an NSTreeController.

2009/10/10 Joshua Garnham <email@hidden>

>Hi,
>
>>I am wondering how I could delete an object depending on it's title for the CoreData 'name' property I have.
>>To Add an Object I use this code:
>>NSManagedObjectContext *moc = [self managedObjectContext];
>>JGManagedObject *theParent =
>>    [NSEntityDescription insertNewObjectForEntityForName:@"projects"
>>                                  inManagedObjectContext:moc];
>>[theParent setValue:nil forKey:@"parent"];
>>// This is where you add the title from the string array
>>[theParent setValue:@"myTitle" forKey:@"name"];
>>[theParent setValue:[NSNumber numberWithInt:0] forKey:@"position"];
>
>>But I can't seem to find an equivalent function to remove An object.
>
>>You See, I have an array of strings so I was hoping I could loop through it deleting the objects with the title of any of the strings.
>
>>Cheers.
>
>

Didn't I answer this on Stack Overflow? http://stackoverflow.com/questions/1535778/, even posting a suggested method.

You'd be better off posting the actual code that you've tried that you're having trouble with. You've already done so in a comment to me.--
Abizer


Send instant messages to your online friends http://uk.messenger.yahoo.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Removing an Object with A Certain Title from an NSTreeController.
      • From: Quincey Morris <email@hidden>
References: 
 >Removing an Object with A Certain Title from an NSTreeController. (From: Joshua Garnham <email@hidden>)

  • Prev by Date: Re: Snow Leopard: unsupported PointerFunctions configuration was requested
  • Next by Date: Re: using QLPreviewPanel and supporting 10.5
  • Previous by thread: Removing an Object with A Certain Title from an NSTreeController.
  • Next by thread: Re: Removing an Object with A Certain Title from an NSTreeController.
  • Index(es):
    • Date
    • Thread