• 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
Problem with NSPredicate in core data fetch request
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with NSPredicate in core data fetch request


  • Subject: Problem with NSPredicate in core data fetch request
  • From: Gideon King <email@hidden>
  • Date: Mon, 14 Mar 2011 00:08:37 +1000

I'm seeing a strange thing with a predicate. When I apply the predicate to a fetch request, it doesn't return any results, but when I do the fetch without the predicate and then use filteredArrayUsingPredicate to filter the results, it has the matching row that I expect.

Here are the results of a query without any predicate:

(gdb) po [[topic managedObjectContext] executeFetchRequest:request error:&error]
<NSCFArray 0x16d15da0>(
<NMAttachmentMO: 0x19e3e780> (entity: Attachment; id: 0x1e095f40 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Attachment/p39C7B8FF-EC6C-451B-9622-F3BDC8DCBB94> ; data: {
    displayName = "Import test map (picture)";
    fileName = "Import test map.png";
    nmObjectId = "72172A92-408D-41FA-AAB6-2132C4641AA5";
    resource = "0x1e06b400 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Resource/pE9C234AD-2A42-4C87-973A-D6B61AD409DD>";
    topic = "0x1e0953b0 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Topic/p5A7F2F62-3B71-434A-9C90-3C8116190D04>";
}),
<NMAttachmentMO: 0x150dace0> (entity: Attachment; id: 0x1e08ee10 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Attachment/pC15B4925-7B19-45D9-9F0D-2CD0BF549DFD> ; data: {
    displayName = "example RSS feed opml";
    fileName = "rss_sharpreader.opml";
    nmObjectId = "DAC4868B-C8BA-41DB-9CC1-6F85193EC7B5";
    resource = "0x36f98c0 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Resource/p2A467945-4674-472B-AA88-73FD47623EE4>";
    topic = "0x1e08dbd0 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Topic/p63A290FB-EAA9-4750-955C-440352D50349>";
}),
<NMAttachmentMO: 0x1e165630> (entity: Attachment; id: 0x1e091ee0 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Attachment/pCD474E6F-4AAA-4E6D-B2FC-478381F590AE> ; data: {
    displayName = nil;
    fileName = "import test mind map(novamind).png";
    nmObjectId = "784A6E81-2EEF-42F5-8D08-05F6B58A8B55";
    resource = "0x1e0fa240 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Resource/p9D511092-DED8-4A29-94D6-8FC998108D82>";
    topic = "0x1e08d830 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Topic/p7A88A2D6-9A96-4B24-BCF2-56FC62BB3D64>";
})
)


And here's my predicate:

(gdb) po predicate
nmObjectId == "784A6E81-2EEF-42F5-8D08-05F6B58A8B55"



If I apply that predicate to the results of my fetch request:

(gdb) po [results filteredArrayUsingPredicate:predicate]
<NSCFArray 0xe71490>(
<NMAttachmentMO: 0x1e165630> (entity: Attachment; id: 0x1e091ee0 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Attachment/pCD474E6F-4AAA-4E6D-B2FC-478381F590AE> ; data: {
    displayName = nil;
    fileName = "import test mind map(novamind).png";
    nmObjectId = "784A6E81-2EEF-42F5-8D08-05F6B58A8B55";
    resource = "0x1e0fa240 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Resource/p9D511092-DED8-4A29-94D6-8FC998108D82>";
    topic = "0x1e08d830 <x-coredata://75C22C98-BAF0-444B-BD95-A4F6B31153D4/Topic/p7A88A2D6-9A96-4B24-BCF2-56FC62BB3D64>";
})
)


So all that's as expected, but if I set exactly that predicate on my fetch request, no results match:

(gdb) call (void)[request setPredicate:predicate]
(gdb) po [[topic managedObjectContext] executeFetchRequest:request error:&error]
<NSCFArray 0x37b5a50>(
)


I am really mystified by this - I can't understand why it would not work when applied to a fetch request, but would work when applied to the array of results.

Any suggestions?


Here's my code which returns 0 rows:

	NSString *attachmentID = [[url path] lastPathComponent];

	NSFetchRequest *request = [[NSFetchRequest alloc] init];
	NSError *error = nil;
	NSEntityDescription *entity = [NSEntityDescription entityForName:kNMAttachmentEntityKey inManagedObjectContext:[topic managedObjectContext]];

	[request setEntity:entity];
	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nmObjectId == %@", attachmentID];
	[request setPredicate:predicate];

	NSArray *results = [[topic managedObjectContext] executeFetchRequest:request error:&error];
	[request release];






Regards

Gideon






_______________________________________________

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: Problem with NSPredicate in core data fetch request
      • From: Andreas Grosam <email@hidden>
  • Prev by Date: Re: Using the same typedef in multiple files
  • Next by Date: Re: Assertion failure in -[MPMoviePlayerControllerNew _moviePlayerDidBecomeActiveNotification:]
  • Previous by thread: Re: Using the same typedef in multiple files
  • Next by thread: Re: Problem with NSPredicate in core data fetch request
  • Index(es):
    • Date
    • Thread