6

I have tried the following using an NSPredicate and am not getting the results I would expect:

NSFetchRequest request = new NSFetchRequest ();
request.Entity = NSEntityDescription.EntityForName("Entity", managedObjectContext);

NSSortDescriptor sort = new NSSortDescriptor ("date", false);
request.SortDescriptors = new NSSortDescriptor[1] { sort };
request.Predicate = NSPredicate.FromFormat("stringProperty == %@", new NSObject[1]{new NSString("someString")});

error = null;
NSObject[] results = managedObjectContext.ExecuteFetchRequest (request, out error);

Is NSPredicate supported in the current stable version of MonoTouch (5.0) or am I doing something wrong?

poupou
  • 43,413
  • 6
  • 77
  • 174
cmour
  • 598
  • 6
  • 13
  • Hard to tell with a snippet. You need to post a self-contained test case – miguel.de.icaza Oct 14 '11 at 14:34
  • Thanks for the response. The snippet above works great without the line setting the predicate. As soon as I set the predicate I don't get any results back from the fetch (when I would expect to from the data and the predicate that is being set). I figured either predicates aren't supported yet or I'm creating the predicate incorrectly. Are there any samples of using a predicate in MonoTouch? – cmour Oct 14 '11 at 15:29
  • I had a quick look and did not find any sample code, so it could be a bug (it does not look to be very commonly used). Could you provide us (here or by filling a bug report on http://bugzilla.xamarin.com) a small, self-contained, test case so we can try to pinpoint the issue ? – poupou Oct 18 '11 at 20:16
  • I have logged a bug (http://bugzilla.xamarin.com/show_bug.cgi?id=2282). – cmour Nov 30 '11 at 23:13

1 Answers1

0

wow, You're really saving lines of programming here. It is hard to tell with that snippet, but... My best suggestion is to break those lines into more lines, like

NSPredicate *myPredicate = ...
if (myPredicate) {
NSLog (@"Predicate exists");
}

And keep going like that line by line to make sure you're getting the right feedback. That's what I do. Might help a little

Farini
  • 923
  • 1
  • 18
  • 35
  • So, are you saying that setting a predicate on a fetch request works for you in MonoTouch? – cmour Nov 30 '11 at 20:56