-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMPredicate.h
172 lines (120 loc) · 6.92 KB
/
SMPredicate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* Copyright 2012-2013 StackMob
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <CoreLocation/CoreLocation.h>
#import "SMGeoPoint.h"
#define GEOQUERY_FIELD @"field"
#define GEOQUERY_MILES @"miles"
#define GEOQUERY_KILOMETERS @"kilometers"
#define GEOQUERY_LAT @"latitude"
#define GEOQUERY_LONG @"longitude"
#define GEOQUERY_COORDINATE @"coordinate"
#define GEOQUERY_SW_BOUND @"sw"
#define GEOQUERY_NE_BOUND @"ne"
typedef enum {
SMGeoQueryWithinMilesOperatorType = 0,
SMGeoQueryWithinKilometersOperatorType = 1,
SMGeoQueryWithinBoundsOperatorType = 2,
SMGeoQueryNearOperatorType = 3
} SMPredicateOperatorType;
/**
`SMPredicate` is a subclass of `NSPredicate`, with additional methods to build predicates that are specific to the StackMob API.
**Important:** Fetching from the cache using `SMPredicate` is not supported, and will return an empty array of results. Similarly, when a fetch is performed from the network (StackMob), any results are not cached.
## References ##
[Apple's NSPredicate class reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/Reference/NSPredicate.html)
*/
@interface SMPredicate : NSPredicate
@property (strong, nonatomic, readonly) NSDictionary *predicateDictionary;
@property (nonatomic, readonly) SMPredicateOperatorType sm_predicateOperatorType;
#pragma mark - Where clauses
/**
Add the predicate criteria: `field`'s location is within `miles` of `point`.
StackMob will generate a field `distance` and insert it into the response. This field is the distance between the query `field`'s location and `point`.
@param field The geo field in the StackMob schema that is to be compared.
@param miles Distance in miles.
@param point The point around which to search.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field isWithin:(CLLocationDistance)miles milesOf:(CLLocationCoordinate2D)point;
/**
Add the predicate criteria: `field`'s location is within `miles` of `geoPoint`.
StackMob will generate a field `distance` and insert it into the response. This field is the distance between the query `field`'s location and `geoPoint`.
@param field The geo field in the StackMob schema that is to be compared.
@param miles Distance in miles.
@param geoPoint The SMGeoPoint around which to search.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field isWithin:(CLLocationDistance)miles milesOfGeoPoint:(SMGeoPoint *)geoPoint;
/**
Add the predicate criteria: `field`'s location is within `kilometers` of `point`.
StackMob will generate a field `distance` and insert it into the response. This field is the distance between the query `field`'s location and `point`.
@param field The geo field in the StackMob schema that is to be compared.
@param kilometers Distance in kilometers.
@param point The point around which to search.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field isWithin:(CLLocationDistance)kilometers kilometersOf:(CLLocationCoordinate2D)point;
/**
Add the predicate criteria: `field`'s location is within `kilometers` of `geoPoint`.
StackMob will generate a field `distance` and insert it into the response. This field is the distance between the query `field`'s location and `geoPoint`.
@param field The geo field in the StackMob schema that is to be compared.
@param kilometers Distance in kilometers.
@param geoPoint The SMGeoPoint around which to search.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field isWithin:(CLLocationDistance)kilometers kilometersOfGeoPoint:(SMGeoPoint *)geoPoint;
/**
Add the predicate criteria: `field`'s location falls within the bounding box with corners `sw` and `ne`.
@param field The geo field in the StackMob schema that is to be compared.
@param sw Location of the bounding box's southwest corner.
@param ne Location of the bounding box's northeast corner.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field isWithinBoundsWithSWCorner:(CLLocationCoordinate2D)sw andNECorner:(CLLocationCoordinate2D)ne;
/**
Add the predicate criteria: `field`'s location falls within the bounding box with corners `sw` and `ne`.
@param field The geo field in the StackMob schema that is to be compared.
@param sw SMGeoPoint of the bounding box's southwest corner.
@param ne SMGeoPoint of the bounding box's northeast corner.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field isWithinBoundsWithSWGeoPoint:(SMGeoPoint *)sw andNEGeoPoint:(SMGeoPoint *)ne;
/**
Add the predicate criteria: `field`'s location near point.
StackMob will insert a field `distance` and insert it into the response. This field is the distance between the query `field`'s location and `point`.
@note You probably want to apply a limit when including this predicate or you may end up with more results than intended.
@param field The geo field in the StackMob schema that is to be compared.
@param point The reference location.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field near:(CLLocationCoordinate2D)point;
/**
Add the predicate criteria: `field`'s location near point.
StackMob will insert a field `distance` and insert it into the response. This field is the distance between the query `field`'s location and `geoPoint`.
@note You probably want to apply a limit when including this predicate or you may end up with more results than intended.
@param field The geo field in the StackMob schema that is to be compared.
@param geoPoint The reference SMGeoPoint.
@return An SMPredicate instance ready to be added to a fetch request.
@since Available in iOS SDK 1.3.0 and later.
*/
+ (SMPredicate *)predicateWhere:(NSString *)field nearGeoPoint:(SMGeoPoint *)geoPoint;
@end