-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPFQuery.h
More file actions
890 lines (641 loc) · 30.2 KB
/
PFQuery.h
File metadata and controls
890 lines (641 loc) · 30.2 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
//
// PFQuery.h
//
// Copyright 2011-present Parse Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
#import <Parse/PFConstants.h>
#import <Parse/PFGeoPoint.h>
#import <Parse/PFObject.h>
#import <Parse/PFUser.h>
#else
#import <ParseOSX/PFConstants.h>
#import <ParseOSX/PFGeoPoint.h>
#import <ParseOSX/PFObject.h>
#import <ParseOSX/PFUser.h>
#endif
PF_ASSUME_NONNULL_BEGIN
@class BFTask;
/*!
The `PFQuery` class defines a query that is used to query for <PFObject>s.
*/
@interface PFQuery : NSObject <NSCopying>
///--------------------------------------
/// @name Creating a Query for a Class
///--------------------------------------
/*!
@abstract Initializes the query with a class name.
@param className The class name.
*/
- (instancetype)initWithClassName:(NSString *)className;
/*!
@abstract Returns a `PFQuery` for a given class.
@param className The class to query on.
@returns A `PFQuery` object.
*/
+ (instancetype)queryWithClassName:(NSString *)className;
/*!
@abstract Creates a PFQuery with the constraints given by predicate.
@discussion The following types of predicates are supported:
- Simple comparisons such as `=`, `!=`, `<`, `>`, `<=`, `>=`, and `BETWEEN` with a key and a constant.
- Containment predicates, such as `x IN {1, 2, 3}`.
- Key-existence predicates, such as `x IN SELF`.
- BEGINSWITH expressions.
- Compound predicates with `AND`, `OR`, and `NOT`.
- SubQueries with `key IN %@`, subquery.
The following types of predicates are NOT supported:
- Aggregate operations, such as `ANY`, `SOME`, `ALL`, or `NONE`.
- Regular expressions, such as `LIKE`, `MATCHES`, `CONTAINS`, or `ENDSWITH`.
- Predicates comparing one key to another.
- Complex predicates with many ORed clauses.
@param className The class to query on.
@param predicate The predicate to create conditions from.
*/
+ (instancetype)queryWithClassName:(NSString *)className predicate:(PF_NULLABLE NSPredicate *)predicate;
/*!
The class name to query for.
*/
@property (nonatomic, strong) NSString *parseClassName;
///--------------------------------------
/// @name Adding Basic Constraints
///--------------------------------------
/*!
@abstract Make the query include PFObjects that have a reference stored at the provided key.
@discussion This has an effect similar to a join. You can use dot notation to specify which fields in
the included object are also fetch.
@param key The key to load child <PFObject>s for.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)includeKey:(NSString *)key;
/*!
@abstract Make the query restrict the fields of the returned <PFObject>s to include only the provided keys.
@discussion If this is called multiple times, then all of the keys specified in each of the calls will be included.
@param keys The keys to include in the result.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)selectKeys:(NSArray *)keys;
/*!
@abstract Add a constraint that requires a particular key exists.
@param key The key that should exist.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKeyExists:(NSString *)key;
/*!
@abstract Add a constraint that requires a key not exist.
@param key The key that should not exist.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKeyDoesNotExist:(NSString *)key;
/*!
@abstract Add a constraint to the query that requires a particular key's object to be equal to the provided object.
@param key The key to be constrained.
@param object The object that must be equalled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key equalTo:(id)object;
/*!
@abstract Add a constraint to the query that requires a particular key's object to be less than the provided object.
@param key The key to be constrained.
@param object The object that provides an upper bound.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key lessThan:(id)object;
/*!
@abstract Add a constraint to the query that requires a particular key's object
to be less than or equal to the provided object.
@param key The key to be constrained.
@param object The object that must be equalled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key lessThanOrEqualTo:(id)object;
/*!
@abstract Add a constraint to the query that requires a particular key's object
to be greater than the provided object.
@param key The key to be constrained.
@param object The object that must be equalled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key greaterThan:(id)object;
/*!
@abstract Add a constraint to the query that requires a particular key's
object to be greater than or equal to the provided object.
@param key The key to be constrained.
@param object The object that must be equalled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key greaterThanOrEqualTo:(id)object;
/*!
@abstract Add a constraint to the query that requires a particular key's object
to be not equal to the provided object.
@param key The key to be constrained.
@param object The object that must not be equalled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key notEqualTo:(id)object;
/*!
@abstract Add a constraint to the query that requires a particular key's object
to be contained in the provided array.
@param key The key to be constrained.
@param array The possible values for the key's object.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key containedIn:(NSArray *)array;
/*!
@abstract Add a constraint to the query that requires a particular key's object
not be contained in the provided array.
@param key The key to be constrained.
@param array The list of values the key's object should not be.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key notContainedIn:(NSArray *)array;
/*!
@abstract Add a constraint to the query that requires a particular key's array
contains every element of the provided array.
@param key The key to be constrained.
@param array The array of values to search for.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key containsAllObjectsInArray:(NSArray *)array;
///--------------------------------------
/// @name Adding Location Constraints
///--------------------------------------
/*!
@abstract Add a constraint to the query that requires a particular key's coordinates (specified via <PFGeoPoint>)
be near a reference point.
@discussion Distance is calculated based on angular distance on a sphere. Results will be sorted by distance
from reference point.
@param key The key to be constrained.
@param geopoint The reference point represented as a <PFGeoPoint>.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key nearGeoPoint:(PFGeoPoint *)geopoint;
/*!
@abstract Add a constraint to the query that requires a particular key's coordinates (specified via <PFGeoPoint>)
be near a reference point and within the maximum distance specified (in miles).
@discussion Distance is calculated based on a spherical coordinate system.
Results will be sorted by distance (nearest to farthest) from the reference point.
@param key The key to be constrained.
@param geopoint The reference point represented as a <PFGeoPoint>.
@param maxDistance Maximum distance in miles.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key
nearGeoPoint:(PFGeoPoint *)geopoint
withinMiles:(double)maxDistance;
/*!
@abstract Add a constraint to the query that requires a particular key's coordinates (specified via <PFGeoPoint>)
be near a reference point and within the maximum distance specified (in kilometers).
@discussion Distance is calculated based on a spherical coordinate system.
Results will be sorted by distance (nearest to farthest) from the reference point.
@param key The key to be constrained.
@param geopoint The reference point represented as a <PFGeoPoint>.
@param maxDistance Maximum distance in kilometers.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key
nearGeoPoint:(PFGeoPoint *)geopoint
withinKilometers:(double)maxDistance;
/*!
Add a constraint to the query that requires a particular key's coordinates (specified via <PFGeoPoint>) be near
a reference point and within the maximum distance specified (in radians). Distance is calculated based on
angular distance on a sphere. Results will be sorted by distance (nearest to farthest) from the reference point.
@param key The key to be constrained.
@param geopoint The reference point as a <PFGeoPoint>.
@param maxDistance Maximum distance in radians.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key
nearGeoPoint:(PFGeoPoint *)geopoint
withinRadians:(double)maxDistance;
/*!
@abstract Add a constraint to the query that requires a particular key's coordinates (specified via <PFGeoPoint>) be
contained within a given rectangular geographic bounding box.
@param key The key to be constrained.
@param southwest The lower-left inclusive corner of the box.
@param northeast The upper-right inclusive corner of the box.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key withinGeoBoxFromSouthwest:(PFGeoPoint *)southwest toNortheast:(PFGeoPoint *)northeast;
///--------------------------------------
/// @name Adding String Constraints
///--------------------------------------
/*!
@abstract Add a regular expression constraint for finding string values that match the provided regular expression.
@warning This may be slow for large datasets.
@param key The key that the string to match is stored in.
@param regex The regular expression pattern to match.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key matchesRegex:(NSString *)regex;
/*!
@abstract Add a regular expression constraint for finding string values that match the provided regular expression.
@warning This may be slow for large datasets.
@param key The key that the string to match is stored in.
@param regex The regular expression pattern to match.
@param modifiers Any of the following supported PCRE modifiers:
- `i` - Case insensitive search
- `m` - Search across multiple lines of input
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key
matchesRegex:(NSString *)regex
modifiers:(PF_NULLABLE NSString *)modifiers;
/*!
@abstract Add a constraint for finding string values that contain a provided substring.
@warning This will be slow for large datasets.
@param key The key that the string to match is stored in.
@param substring The substring that the value must contain.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key containsString:(PF_NULLABLE NSString *)substring;
/*!
@abstract Add a constraint for finding string values that start with a provided prefix.
@discussion This will use smart indexing, so it will be fast for large datasets.
@param key The key that the string to match is stored in.
@param prefix The substring that the value must start with.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key hasPrefix:(PF_NULLABLE NSString *)prefix;
/*!
@abstract Add a constraint for finding string values that end with a provided suffix.
@warning This will be slow for large datasets.
@param key The key that the string to match is stored in.
@param suffix The substring that the value must end with.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key hasSuffix:(PF_NULLABLE NSString *)suffix;
///--------------------------------------
/// @name Adding Subqueries
///--------------------------------------
/*!
Returns a `PFQuery` that is the `or` of the passed in queries.
@param queries The list of queries to or together.
@returns An instance of `PFQuery` that is the `or` of the passed in queries.
*/
+ (instancetype)orQueryWithSubqueries:(NSArray *)queries;
/*!
@abstract Adds a constraint that requires that a key's value matches a value in another key
in objects returned by a sub query.
@param key The key that the value is stored.
@param otherKey The key in objects in the returned by the sub query whose value should match.
@param query The query to run.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key
matchesKey:(NSString *)otherKey
inQuery:(PFQuery *)query;
/*!
@abstract Adds a constraint that requires that a key's value `NOT` match a value in another key
in objects returned by a sub query.
@param key The key that the value is stored.
@param otherKey The key in objects in the returned by the sub query whose value should match.
@param query The query to run.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key
doesNotMatchKey:(NSString *)otherKey
inQuery:(PFQuery *)query;
/*!
@abstract Add a constraint that requires that a key's value matches a `PFQuery` constraint.
@warning This only works where the key's values are <PFObject>s or arrays of <PFObject>s.
@param key The key that the value is stored in
@param query The query the value should match
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key matchesQuery:(PFQuery *)query;
/*!
@abstract Add a constraint that requires that a key's value to not match a `PFQuery` constraint.
@warning This only works where the key's values are <PFObject>s or arrays of <PFObject>s.
@param key The key that the value is stored in
@param query The query the value should not match
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key doesNotMatchQuery:(PFQuery *)query;
///--------------------------------------
/// @name Sorting
///--------------------------------------
/*!
@abstract Sort the results in *ascending* order with the given key.
@param key The key to order by.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)orderByAscending:(NSString *)key;
/*!
@abstract Additionally sort in *ascending* order by the given key.
@discussion The previous keys provided will precedence over this key.
@param key The key to order by.
*/
- (instancetype)addAscendingOrder:(NSString *)key;
/*!
@abstract Sort the results in *descending* order with the given key.
@param key The key to order by.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)orderByDescending:(NSString *)key;
/*!
@abstract Additionally sort in *descending* order by the given key.
@discussion The previous keys provided will precedence over this key.
@param key The key to order by.
*/
- (instancetype)addDescendingOrder:(NSString *)key;
/*!
@abstract Sort the results using a given sort descriptor.
@warning If a `sortDescriptor` has custom `selector` or `comparator` - they aren't going to be used.
@param sortDescriptor The `NSSortDescriptor` to use to sort the results of the query.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)orderBySortDescriptor:(NSSortDescriptor *)sortDescriptor;
/*!
@abstract Sort the results using a given array of sort descriptors.
@warning If a `sortDescriptor` has custom `selector` or `comparator` - they aren't going to be used.
@param sortDescriptors An array of `NSSortDescriptor` objects to use to sort the results of the query.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)orderBySortDescriptors:(PF_NULLABLE NSArray *)sortDescriptors;
///--------------------------------------
/// @name Getting Objects by ID
///--------------------------------------
/*!
@abstract Returns a <PFObject> with a given class and id.
@param objectClass The class name for the object that is being requested.
@param objectId The id of the object that is being requested.
@returns The <PFObject> if found. Returns `nil` if the object isn't found, or if there was an error.
*/
+ (PF_NULLABLE PFObject *)getObjectOfClass:(NSString *)objectClass objectId:(NSString *)objectId;
/*!
@abstract Returns a <PFObject> with a given class and id and sets an error if necessary.
@param objectClass The class name for the object that is being requested.
@param objectId The id of the object that is being requested.
@param error Pointer to an `NSError` that will be set if necessary.
@returns The <PFObject> if found. Returns `nil` if the object isn't found, or if there was an `error`.
*/
+ (PF_NULLABLE PFObject *)getObjectOfClass:(NSString *)objectClass
objectId:(NSString *)objectId
error:(NSError **)error;
/*!
@abstract Returns a <PFObject> with the given id.
@warning This method mutates the query.
It will reset limit to `1`, skip to `0` and remove all conditions, leaving only `objectId`.
@param objectId The id of the object that is being requested.
@returns The <PFObject> if found. Returns nil if the object isn't found, or if there was an error.
*/
- (PF_NULLABLE PFObject *)getObjectWithId:(NSString *)objectId;
/*!
@abstract Returns a <PFObject> with the given id and sets an error if necessary.
@warning This method mutates the query.
It will reset limit to `1`, skip to `0` and remove all conditions, leaving only `objectId`.
@param objectId The id of the object that is being requested.
@param error Pointer to an `NSError` that will be set if necessary.
@returns The <PFObject> if found. Returns nil if the object isn't found, or if there was an error.
*/
- (PF_NULLABLE PFObject *)getObjectWithId:(NSString *)objectId error:(NSError **)error;
/*!
@abstract Gets a <PFObject> asynchronously and calls the given block with the result.
@warning This method mutates the query.
It will reset limit to `1`, skip to `0` and remove all conditions, leaving only `objectId`.
@param objectId The id of the object that is being requested.
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)getObjectInBackgroundWithId:(NSString *)objectId;
/*!
@abstract Gets a <PFObject> asynchronously and calls the given block with the result.
@warning This method mutates the query.
It will reset limit to `1`, skip to `0` and remove all conditions, leaving only `objectId`.
@param objectId The id of the object that is being requested.
@param block The block to execute.
The block should have the following argument signature: `^(NSArray *object, NSError *error)`
*/
- (void)getObjectInBackgroundWithId:(NSString *)objectId
block:(PF_NULLABLE PFObjectResultBlock)block;
/*
@abstract Gets a <PFObject> asynchronously.
This mutates the PFQuery. It will reset limit to `1`, skip to `0` and remove all conditions, leaving only `objectId`.
@param objectId The id of the object being requested.
@param target The target for the callback selector.
@param selector The selector for the callback.
It should have the following signature: `(void)callbackWithResult:(id)result error:(NSError *)error`.
Result will be `nil` if error is set and vice versa.
*/
- (void)getObjectInBackgroundWithId:(NSString *)objectId
target:(PF_NULLABLE_S id)target
selector:(PF_NULLABLE_S SEL)selector;
///--------------------------------------
/// @name Getting User Objects
///--------------------------------------
/*!
@abstract Returns a <PFUser> with a given id.
@param objectId The id of the object that is being requested.
@returns The PFUser if found. Returns nil if the object isn't found, or if there was an error.
*/
+ (PF_NULLABLE PFUser *)getUserObjectWithId:(NSString *)objectId;
/*!
Returns a PFUser with a given class and id and sets an error if necessary.
@param objectId The id of the object that is being requested.
@param error Pointer to an NSError that will be set if necessary.
@result The PFUser if found. Returns nil if the object isn't found, or if there was an error.
*/
+ (PF_NULLABLE PFUser *)getUserObjectWithId:(NSString *)objectId
error:(NSError **)error;
/*!
@deprecated Please use [PFUser query] instead.
*/
+ (instancetype)queryForUser PARSE_DEPRECATED("Use [PFUser query] instead.");
///--------------------------------------
/// @name Getting all Matches for a Query
///--------------------------------------
/*!
@abstract Finds objects *synchronously* based on the constructed query.
@returns Returns an array of <PFObject> objects that were found.
*/
- (PF_NULLABLE NSArray *)findObjects;
/*!
@abstract Finds objects *synchronously* based on the constructed query and sets an error if there was one.
@param error Pointer to an `NSError` that will be set if necessary.
@returns Returns an array of <PFObject> objects that were found.
*/
- (PF_NULLABLE NSArray *)findObjects:(NSError **)error;
/*!
@abstract Finds objects *asynchronously* and sets the `NSArray` of <PFObject> objects as a result of the task.
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)findObjectsInBackground;
/*!
@abstract Finds objects *asynchronously* and calls the given block with the results.
@param block The block to execute.
It should have the following argument signature: `^(NSArray *objects, NSError *error)`
*/
- (void)findObjectsInBackgroundWithBlock:(PF_NULLABLE PFArrayResultBlock)block;
/*
@abstract Finds objects *asynchronously* and calls the given callback with the results.
@param target The object to call the selector on.
@param selector The selector to call.
It should have the following signature: `(void)callbackWithResult:(id)result error:(NSError *)error`.
Result will be `nil` if error is set and vice versa.
*/
- (void)findObjectsInBackgroundWithTarget:(PF_NULLABLE_S id)target selector:(PF_NULLABLE_S SEL)selector;
///--------------------------------------
/// @name Getting the First Match in a Query
///--------------------------------------
/*!
@abstract Gets an object *synchronously* based on the constructed query.
@warning This method mutates the query. It will reset the limit to `1`.
@returns Returns a <PFObject>, or `nil` if none was found.
*/
- (PF_NULLABLE PFObject *)getFirstObject;
/*!
@abstract Gets an object *synchronously* based on the constructed query and sets an error if any occurred.
@warning This method mutates the query. It will reset the limit to `1`.
@param error Pointer to an `NSError` that will be set if necessary.
@returns Returns a <PFObject>, or `nil` if none was found.
*/
- (PF_NULLABLE PFObject *)getFirstObject:(NSError **)error;
/*!
@abstract Gets an object *asynchronously* and sets it as a result of the task.
@warning This method mutates the query. It will reset the limit to `1`.
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)getFirstObjectInBackground;
/*!
@abstract Gets an object *asynchronously* and calls the given block with the result.
@warning This method mutates the query. It will reset the limit to `1`.
@param block The block to execute.
It should have the following argument signature: `^(PFObject *object, NSError *error)`.
`result` will be `nil` if `error` is set OR no object was found matching the query.
`error` will be `nil` if `result` is set OR if the query succeeded, but found no results.
*/
- (void)getFirstObjectInBackgroundWithBlock:(PF_NULLABLE PFObjectResultBlock)block;
/*
@abstract Gets an object *asynchronously* and calls the given callback with the results.
@warning This method mutates the query. It will reset the limit to `1`.
@param target The object to call the selector on.
@param selector The selector to call.
It should have the following signature: `(void)callbackWithResult:(PFObject *)result error:(NSError *)error`.
`result` will be `nil` if `error` is set OR no object was found matching the query.
`error` will be `nil` if `result` is set OR if the query succeeded, but found no results.
*/
- (void)getFirstObjectInBackgroundWithTarget:(PF_NULLABLE_S id)target selector:(PF_NULLABLE_S SEL)selector;
///--------------------------------------
/// @name Counting the Matches in a Query
///--------------------------------------
/*!
@abstract Counts objects *synchronously* based on the constructed query.
@returns Returns the number of <PFObject> objects that match the query, or `-1` if there is an error.
*/
- (NSInteger)countObjects;
/*!
@abstract Counts objects *synchronously* based on the constructed query and sets an error if there was one.
@param error Pointer to an `NSError` that will be set if necessary.
@returns Returns the number of <PFObject> objects that match the query, or `-1` if there is an error.
*/
- (NSInteger)countObjects:(NSError **)error;
/*!
@abstract Counts objects *asynchronously* and sets `NSNumber` with count as a result of the task.
@returns The task, that encapsulates the work being done.
*/
- (BFTask *)countObjectsInBackground;
/*!
@abstract Counts objects *asynchronously* and calls the given block with the counts.
@param block The block to execute.
It should have the following argument signature: `^(int count, NSError *error)`
*/
- (void)countObjectsInBackgroundWithBlock:(PF_NULLABLE PFIntegerResultBlock)block;
/*
@abstract Counts objects *asynchronously* and calls the given callback with the count.
@param target The object to call the selector on.
@param selector The selector to call.
It should have the following signature: `(void)callbackWithResult:(NSNumber *)result error:(NSError *)error`.
*/
- (void)countObjectsInBackgroundWithTarget:(PF_NULLABLE_S id)target selector:(PF_NULLABLE_S SEL)selector;
///--------------------------------------
/// @name Cancelling a Query
///--------------------------------------
/*!
@abstract Cancels the current network request (if any). Ensures that callbacks won't be called.
*/
- (void)cancel;
///--------------------------------------
/// @name Paginating Results
///--------------------------------------
/*!
@abstract A limit on the number of objects to return. The default limit is `100`, with a
maximum of 1000 results being returned at a time.
@warning If you are calling `findObjects` with `limit = 1`, you may find it easier to use `getFirst` instead.
*/
@property (nonatomic, assign) NSInteger limit;
/*!
@abstract The number of objects to skip before returning any.
*/
@property (nonatomic, assign) NSInteger skip;
///--------------------------------------
/// @name Controlling Caching Behavior
///--------------------------------------
/*!
@abstract The cache policy to use for requests.
Not allowed when Pinning is enabled.
@see fromLocalDatastore
@see fromPin
@see fromPinWithName:
*/
@property (assign, readwrite) PFCachePolicy cachePolicy;
/* !
@abstract The age after which a cached value will be ignored
*/
@property (assign, readwrite) NSTimeInterval maxCacheAge;
/*!
@abstract Returns whether there is a cached result for this query.
@result `YES` if there is a cached result for this query, otherwise `NO`.
*/
- (BOOL)hasCachedResult;
/*!
@abstract Clears the cached result for this query. If there is no cached result, this is a noop.
*/
- (void)clearCachedResult;
/*!
@abstract Clears the cached results for all queries.
*/
+ (void)clearAllCachedResults;
///--------------------------------------
/// @name Query Source
///--------------------------------------
/*!
@abstract Change the source of this query to all pinned objects.
@warning Requires Local Datastore to be enabled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
@see cachePolicy
*/
- (instancetype)fromLocalDatastore;
/*!
@abstract Change the source of this query to the default group of pinned objects.
@warning Requires Local Datastore to be enabled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
@see PFObjectDefaultPin
@see cachePolicy
*/
- (instancetype)fromPin;
/*!
@abstract Change the source of this query to a specific group of pinned objects.
@warning Requires Local Datastore to be enabled.
@param name The pinned group.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
@see PFObjectDefaultPin
@see cachePolicy
*/
- (instancetype)fromPinWithName:(PF_NULLABLE NSString *)name;
/*!
@abstract Ignore ACLs when querying from the Local Datastore.
@discussion This is particularly useful when querying for objects with Role based ACLs set on them.
@warning Requires Local Datastore to be enabled.
@returns The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)ignoreACLs;
///--------------------------------------
/// @name Advanced Settings
///--------------------------------------
/*!
@abstract Whether or not performance tracing should be done on the query.
@warning This should not be set to `YES` in most cases.
*/
@property (nonatomic, assign) BOOL trace;
@end
PF_ASSUME_NONNULL_END