• 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
Core Data and +[NSExpression expressionForFunction:...]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data and +[NSExpression expressionForFunction:...]


  • Subject: Core Data and +[NSExpression expressionForFunction:...]
  • From: Ron Aldrich <email@hidden>
  • Date: Wed, 25 Nov 2009 17:08:51 -0800

Hello All,

I'm trying to query a Core Data database which contains geoLocation information for all of the objects of type "Photo" which are within a specified distance of a target point, using the following code.

- (NSArray*) photosNearLatitude: (NSNumber*) inLatitude
                      longitude: (NSNumber*) inLongitude
{
  NSExpression *theLHS = [NSExpression expressionForFunction: [NSExpression expressionForEvaluatedObject]
                                                selectorName: @"distanceFromLatitude:longitude:"
                                                   arguments: [NSArray arrayWithObjects:
                                                               [NSExpression expressionForConstantValue: inLatitude],
                                                               [NSExpression expressionForConstantValue: inLongitude],
                                                               nil]];

  NSExpression* theRHS = [NSExpression expressionForConstantValue: [NSNumber numberWithDouble: 0.1]];

  NSPredicate* thePredicate = [NSComparisonPredicate predicateWithLeftExpression: theLHS
                                                                 rightExpression: theRHS
                                                                        modifier: NSDirectPredicateModifier
                                                                            type: NSLessThanOrEqualToPredicateOperatorType
                                                                         options: 0];

  NSManagedObjectContext* theManagedObjectContext = [self managedObjectContext];

  NSFetchRequest* theFetch = [[[NSFetchRequest alloc] init] autorelease];
  theFetch.entity = [NSEntityDescription entityForName: @"Photo"
                                inManagedObjectContext: theManagedObjectContext];
  theFetch.predicate = thePredicate;

  NSError* theError = NULL;
  NSArray* theResults = [theManagedObjectContext executeFetchRequest: theFetch
                                                               error: &theError];

  return theResults;
}

The "Photo" class has the following selector.

- (NSNumber*) distanceFromLatitude: (NSNumber*) inLatitude
                         longitude: (NSNumber*) inLongitude

My problem is that when I call "executeFetchRequest", an exception occurs:

2009-11-25 16:55:20.633 Serendipity[8498:a0f] Unsupported function expression FUNCTION(SELF, "distanceFromLatitude:longitude:" , 47.71283333333334, -122.225)

-[Photo distanceFromLatitude:longitude:] is never called.

Can anyone suggest what might be going wrong?

- Ron Aldrich

_______________________________________________

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: Core Data and +[NSExpression expressionForFunction:...]
      • From: Alexander Spohr <email@hidden>
  • Prev by Date: Re: Drawing: The Right place to keep bounds
  • Next by Date: Re: EXC_BAD_ACCESS when calling NSOpenPanel
  • Previous by thread: Re: NSOutlineView - how to have a default item selected
  • Next by thread: Re: Core Data and +[NSExpression expressionForFunction:...]
  • Index(es):
    • Date
    • Thread