开发者

convert sql statement for use in core data

开发者 https://www.devze.com 2023-03-25 03:09 出处:网络
I have this statement that im trying to figure out how to use in core data. SELECT (3963.0 *acos(sin(\".$StartLat.\"/57.2958) *sin(latitude/57.2958) + cos(\".$StartLat.\"/57.2958) *cos(latitude/57.2

I have this statement that im trying to figure out how to use in core data.

SELECT 
(3963.0 *  acos(sin(".$StartLat."/57.2958) *   sin(latitude/57.2958) + cos(".$StartLat."/57.2958) *  cos(latitude/57.2958) * cos(longitude/57.2958 - ".$StartLon."/57.2958)))   as distance 
FROM locations
ORDER BY distance
LIMIT 0, 10

Im guessing this is the part i need to modify:

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Title" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] ini开发者_StackOverflow社区tWithObjects:sortDescriptor, nil];

[fetchRequest setSortDescriptors:sortDescriptors];

Thanks in advance.


Simple answer: you can't.

Real answer: you haven't understood what Core Data is.

Core Data is not a database. It is not SQL. It is not a relational database in any way shape or form.

Core Data is a framework for abstracting the persistence of objects from their in-memory representation. It is an object management framework. You interact with it via objects. You do not create queries. You do not execute SQL. You request objects. Full blown, NSObject subclasses.

Please go read the Core Data Programming Guide.

(sorry if this comes off as harsh, but this is such a commonly mis-understood thing that it bears being totally explicit)

0

精彩评论

暂无评论...
验证码 换一张
取 消