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

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


  • Subject: Re: Core Data and +[NSExpression expressionForFunction:...]
  • From: Ron Aldrich <email@hidden>
  • Date: Fri, 27 Nov 2009 12:23:22 -0800

Atze,

The documentation for expressionForFunction: makes a point of stating:

> This expression effectively allows your application to invoke any method on any object it can navigate to at runtime. You must consider the security implications of this type of evaluation.

Which would indicate that there is some way to make this work.  I agree that speed would be a problem, but I could address that by adding a bounds check into the expression.

At this point, it's becoming academic, because I know that I can solve the problem with a bounds check, and post process - but I'd very much like to understand why this isn't working.

- Ron

On Nov 25, 2009, at 11:34 PM, Alexander Spohr wrote:

> Ron,
>
> I am not sure if that works at all. I never fetched using methods that are not part of the database as a qualifier. Your code has to be very slow because it would need to fetch all Photos and then call distanceFromLatitude:longitude: on each.
>
> Why not qualify directly using a bounding rect?
> latitude > inLatitude - 0.1 && latitude < inLatitude + 0.1 &&
> longitude > inLongitude - 0.1 && longitude < inLongitude + 0.1
> The database can figure that out very fast.
>
> 	atze
>
>
>
> Am 26.11.2009 um 02:08 schrieb Ron Aldrich:
>
>> 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: Jerry Krinock <email@hidden>
References: 
 >Core Data and +[NSExpression expressionForFunction:...] (From: Ron Aldrich <email@hidden>)
 >Re: Core Data and +[NSExpression expressionForFunction:...] (From: Alexander Spohr <email@hidden>)

  • Prev by Date: Re: NSOutlineView - how to have a default item selected
  • Next by Date: Re: My try/catch block isn't catching exceptions on 10.6
  • Previous by thread: Re: Core Data and +[NSExpression expressionForFunction:...]
  • Next by thread: Re: Core Data and +[NSExpression expressionForFunction:...]
  • Index(es):
    • Date
    • Thread