Skip to content

Commit 3f74697

Browse files
committed
Merge pull request #902 from ParsePlatform/nlutsenko.keypath
Convert constant strings to type-safe macros in PFQueryState.
2 parents f9c5770 + 95dafc8 commit 3f74697

File tree

6 files changed

+62
-40
lines changed

6 files changed

+62
-40
lines changed

Parse/Internal/Query/State/PFMutableQueryState.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
- (void)sortByKey:(NSString *)key ascending:(BOOL)ascending;
6060
- (void)addSortKey:(NSString *)key ascending:(BOOL)ascending;
61-
- (void)addSortKeysFromSortDescriptors:(NSArray *)sortDescriptors;
61+
- (void)addSortKeysFromSortDescriptors:(NSArray<NSSortDescriptor *> *)sortDescriptors;
6262

6363
///--------------------------------------
6464
#pragma mark - Includes
@@ -71,7 +71,7 @@
7171
#pragma mark - Selected Keys
7272
///--------------------------------------
7373

74-
- (void)selectKeys:(NSArray *)keys;
74+
- (void)selectKeys:(NSArray<NSString *> *)keys;
7575

7676
///--------------------------------------
7777
#pragma mark - Redirect

Parse/Internal/Query/State/PFMutableQueryState.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
#import "PFQueryConstants.h"
1212

1313
#import "PFQueryState_Private.h"
14+
#import "PFMacros.h"
1415

1516
@interface PFMutableQueryState () {
16-
NSMutableDictionary *_conditions;
17-
NSMutableArray *_sortKeys;
18-
NSMutableSet *_includedKeys;
19-
NSMutableDictionary *_extraOptions;
17+
NSMutableDictionary<NSString *, id> *_conditions;
18+
NSMutableArray<NSString *> *_sortKeys;
19+
NSMutableSet<NSString *> *_includedKeys;
20+
NSMutableDictionary<NSString *, NSString *> *_extraOptions;
2021
}
2122

2223
@end
@@ -47,10 +48,10 @@ @implementation PFMutableQueryState
4748
+ (NSDictionary *)propertyAttributes {
4849
NSMutableDictionary *attributes = [[super propertyAttributes] mutableCopy];
4950

50-
attributes[@"conditions"] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
51-
attributes[@"sortKeys"] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
52-
attributes[@"includedKeys"] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
53-
attributes[@"extraOptions"] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
51+
attributes[PFQueryStatePropertyName(conditions)] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
52+
attributes[PFQueryStatePropertyName(sortKeys)] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
53+
attributes[PFQueryStatePropertyName(includedKeys)] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
54+
attributes[PFQueryStatePropertyName(extraOptions)] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
5455

5556
return attributes;
5657
}
@@ -133,7 +134,7 @@ - (void)addSortKey:(NSString *)key ascending:(BOOL)ascending {
133134
}
134135
}
135136

136-
- (void)addSortKeysFromSortDescriptors:(NSArray *)sortDescriptors {
137+
- (void)addSortKeysFromSortDescriptors:(NSArray<NSSortDescriptor *> *)sortDescriptors {
137138
[_sortKeys removeAllObjects];
138139
for (NSSortDescriptor *sortDescriptor in sortDescriptors) {
139140
[self addSortKey:sortDescriptor.key ascending:sortDescriptor.ascending];
@@ -164,7 +165,7 @@ - (void)includeKeys:(NSArray<NSString *> *)keys {
164165
#pragma mark - Selected Keys
165166
///--------------------------------------
166167

167-
- (void)selectKeys:(NSArray *)keys {
168+
- (void)selectKeys:(NSArray<NSString *> *)keys {
168169
if (keys) {
169170
_selectedKeys = (_selectedKeys ? [_selectedKeys setByAddingObjectsFromArray:keys] : [NSSet setWithArray:keys]);
170171
} else {

Parse/Internal/Query/State/PFQueryState.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
@property (nonatomic, copy, readonly) NSString *parseClassName;
1919

20-
@property (nonatomic, copy, readonly) NSDictionary *conditions;
20+
@property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *conditions;
2121

22-
@property (nonatomic, copy, readonly) NSArray *sortKeys;
22+
@property (nonatomic, copy, readonly) NSArray<NSString *> *sortKeys;
2323
@property (nonatomic, copy, readonly) NSString *sortOrderString;
2424

25-
@property (nonatomic, copy, readonly) NSSet *includedKeys;
26-
@property (nonatomic, copy, readonly) NSSet *selectedKeys;
27-
@property (nonatomic, copy, readonly) NSDictionary *extraOptions;
25+
@property (nonatomic, copy, readonly) NSSet<NSString *> *includedKeys;
26+
@property (nonatomic, copy, readonly) NSSet<NSString *> *selectedKeys;
27+
@property (nonatomic, copy, readonly) NSDictionary<NSString *, NSString *> *extraOptions;
2828

2929
@property (nonatomic, assign, readonly) NSInteger limit;
3030
@property (nonatomic, assign, readonly) NSInteger skip;

Parse/Internal/Query/State/PFQueryState.m

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#import "PFMutableQueryState.h"
1414
#import "PFPropertyInfo.h"
15+
#import "PFMacros.h"
1516

1617
@implementation PFQueryState
1718

@@ -21,24 +22,24 @@ @implementation PFQueryState
2122

2223
+ (NSDictionary *)propertyAttributes {
2324
return @{
24-
@"parseClassName": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
25-
@"conditions": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
26-
@"sortKeys": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
27-
@"includedKeys": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
28-
@"selectedKeys": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
29-
@"extraOptions": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
30-
31-
@"limit": [PFPropertyAttributes attributes],
32-
@"skip": [PFPropertyAttributes attributes],
33-
@"cachePolicy": [PFPropertyAttributes attributes],
34-
@"maxCacheAge": [PFPropertyAttributes attributes],
35-
36-
@"trace": [PFPropertyAttributes attributes],
37-
@"shouldIgnoreACLs": [PFPropertyAttributes attributes],
38-
@"shouldIncludeDeletingEventually": [PFPropertyAttributes attributes],
39-
@"queriesLocalDatastore": [PFPropertyAttributes attributes],
40-
41-
@"localDatastorePinName": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy]
25+
PFQueryStatePropertyName(parseClassName): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
26+
PFQueryStatePropertyName(conditions): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
27+
PFQueryStatePropertyName(sortKeys): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
28+
PFQueryStatePropertyName(includedKeys): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
29+
PFQueryStatePropertyName(selectedKeys): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
30+
PFQueryStatePropertyName(extraOptions): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
31+
32+
PFQueryStatePropertyName(limit): [PFPropertyAttributes attributes],
33+
PFQueryStatePropertyName(skip): [PFPropertyAttributes attributes],
34+
PFQueryStatePropertyName(cachePolicy): [PFPropertyAttributes attributes],
35+
PFQueryStatePropertyName(maxCacheAge): [PFPropertyAttributes attributes],
36+
37+
PFQueryStatePropertyName(trace): [PFPropertyAttributes attributes],
38+
PFQueryStatePropertyName(shouldIgnoreACLs): [PFPropertyAttributes attributes],
39+
PFQueryStatePropertyName(shouldIncludeDeletingEventually): [PFPropertyAttributes attributes],
40+
PFQueryStatePropertyName(queriesLocalDatastore): [PFPropertyAttributes attributes],
41+
42+
PFQueryStatePropertyName(localDatastorePinName): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy]
4243
};
4344
}
4445

Parse/Internal/Query/State/PFQueryState_Private.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,28 @@
99

1010
#import "PFQueryState.h"
1111

12+
#import "PFMacros.h"
13+
14+
/**
15+
Returns NSString representation of a property on PFQueryState.
16+
17+
@param NAME The name of the property.
18+
19+
@return NSString representaiton of a given property.
20+
*/
21+
#define PFQueryStatePropertyName(NAME) @keypath(PFQueryState, NAME)
22+
1223
@interface PFQueryState () {
1324
@protected
1425
NSString *_parseClassName;
1526

16-
NSDictionary *_conditions;
27+
NSDictionary<NSString *, id> *_conditions;
1728

18-
NSArray *_sortKeys;
29+
NSArray<NSString *> *_sortKeys;
1930

20-
NSSet *_includedKeys;
21-
NSSet *_selectedKeys;
22-
NSDictionary *_extraOptions;
31+
NSSet<NSString *> *_includedKeys;
32+
NSSet<NSString *> *_selectedKeys;
33+
NSDictionary<NSString *, NSString *> *_extraOptions;
2334

2435
NSInteger _limit;
2536
NSInteger _skip;

Tests/Unit/QueryStateUnitTests.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ - (void)testIncludeKeys {
200200
XCTAssertEqualObjects(state.includedKeys, includedKeys);
201201
}
202202

203+
- (void)testIncludeMultipleKeys {
204+
PFMutableQueryState *state = [[PFMutableQueryState alloc] initWithParseClassName:@"Yarr"];
205+
[state includeKeys:@[ @"a", @"b", @"c" ]];
206+
[state includeKey:@"a"];
207+
208+
NSSet *includedKeys = PF_SET(@"a", @"b", @"c");
209+
XCTAssertEqualObjects(state.includedKeys, includedKeys);
210+
}
211+
203212
- (void)testSelectKeys {
204213
PFMutableQueryState *state = [[PFMutableQueryState alloc] initWithParseClassName:@"Yarr"];
205214

0 commit comments

Comments
 (0)