Skip to content

Commit 159c0d6

Browse files
committed
Merge pull request #903 from ParsePlatform/nlutsenko.keypath.acl
Convert constant strings to type-safe macros in PFACLState, PFFileState, PFPushState, PFRelationState.
2 parents 3f74697 + e350de2 commit 159c0d6

File tree

12 files changed

+80
-34
lines changed

12 files changed

+80
-34
lines changed

Parse/Internal/ACL/State/PFACLState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef void (^PFACLStateMutationBlock)(PFMutableACLState *);
1717

1818
@interface PFACLState : PFBaseState<PFBaseStateSubclass, NSCopying, NSMutableCopying>
1919

20-
@property (nonatomic, copy, readonly) NSDictionary *permissions;
20+
@property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *permissions;
2121
@property (nonatomic, assign, readonly, getter=isShared) BOOL shared;
2222

2323
///--------------------------------------

Parse/Internal/ACL/State/PFACLState.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ @implementation PFACLState
1919

2020
+ (NSDictionary *)propertyAttributes {
2121
return @{
22-
@"permissions": [PFPropertyAttributes attributes],
23-
@"shared": [PFPropertyAttributes attributes],
22+
PFACLStatePropertyName(permissions): [PFPropertyAttributes attributes],
23+
PFACLStatePropertyName(shared): [PFPropertyAttributes attributes],
2424
};
2525
}
2626

@@ -30,7 +30,7 @@ + (NSDictionary *)propertyAttributes {
3030

3131
- (instancetype)init {
3232
self = [super init];
33-
if (!self) return nil;
33+
if (!self) return self;
3434

3535
_permissions = @{};
3636
_shared = NO;
@@ -44,7 +44,7 @@ - (instancetype)initWithState:(PFACLState *)otherState {
4444

4545
- (instancetype)initWithState:(PFACLState *)otherState mutatingBlock:(PFACLStateMutationBlock)mutatingBlock {
4646
self = [self initWithState:otherState];
47-
if (!self) return nil;
47+
if (!self) return self;
4848

4949
// Make permissions mutable for the duration of the block.
5050
_permissions = [_permissions mutableCopy];

Parse/Internal/ACL/State/PFACLState_Private.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99

1010
#import "PFACLState.h"
1111

12+
#import "PFMacros.h"
13+
14+
/**
15+
Returns NSString representation of a property on PFACLState
16+
17+
@param NAME The name of the property.
18+
19+
@return NSString representaiton of a given property.
20+
*/
21+
#define PFACLStatePropertyName(NAME) @keypath(PFACLState, NAME)
22+
1223
@interface PFACLState () {
1324
@protected
14-
NSDictionary *_permissions;
25+
NSDictionary<NSString *, id> *_permissions;
1526
BOOL _shared;
1627
}
1728

18-
@property (nonatomic, copy, readwrite) NSDictionary *permissions;
29+
@property (nonatomic, copy, readwrite) NSDictionary<NSString *, id> *permissions;
1930
@property (nonatomic, assign, readwrite, getter=isShared) BOOL shared;
2031

2132
@end

Parse/Internal/ACL/State/PFMutableACLState.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99

1010
#import "PFACLState.h"
1111

12+
NS_ASSUME_NONNULL_BEGIN
13+
1214
@interface PFMutableACLState : PFACLState
1315

14-
@property (nonatomic, copy, readwrite) NSMutableDictionary *permissions;
16+
@property (nonatomic, copy, readwrite) NSMutableDictionary<NSString *, id> *permissions;
1517
@property (nonatomic, assign, readwrite, getter=isShared) BOOL shared;
1618

1719
@end
20+
21+
NS_ASSUME_NONNULL_END

Parse/Internal/ACL/State/PFMutableACLState.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ @implementation PFMutableACLState
2222

2323
- (instancetype)init {
2424
self = [super init];
25-
if (!self) return nil;
25+
if (!self) return self;
2626

2727
_permissions = [NSMutableDictionary dictionary];
2828

Parse/Internal/File/State/PFFileState.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ @implementation PFFileState
2828
///--------------------------------------
2929

3030
+ (NSDictionary *)propertyAttributes {
31-
return @{
32-
@"name" : [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
33-
@"urlString" : [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
34-
@"mimeType" : [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
35-
};
31+
return @{ PFFileStatePropertyName(name) : [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
32+
PFFileStatePropertyName(urlString) : [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
33+
PFFileStatePropertyName(mimeType) : [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy] };
3634
}
3735

3836
///--------------------------------------

Parse/Internal/File/State/PFFileState_Private.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
#import "PFFileState.h"
1111

12+
#import "PFMacros.h"
13+
14+
/**
15+
Returns NSString representation of a property.
16+
17+
@param NAME The name of the property.
18+
19+
@return NSString representation of a given property.
20+
*/
21+
#define PFFileStatePropertyName(NAME) @keypath(PFFileState, NAME)
22+
1223
NS_ASSUME_NONNULL_BEGIN
1324

1425
@interface PFFileState ()

Parse/Internal/Push/State/PFPushState.m

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,40 @@
1414
#import "PFQueryState.h"
1515
#import "PFAssert.h"
1616

17+
NS_ASSUME_NONNULL_BEGIN
18+
1719
@implementation PFPushState
1820

1921
///--------------------------------------
2022
#pragma mark - PFBaseStateSubclass
2123
///--------------------------------------
2224

2325
+ (NSDictionary *)propertyAttributes {
24-
return @{ @"channels": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
25-
@"queryState": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
26-
@"expirationDate": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeStrong],
27-
@"expirationTimeInterval": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeStrong],
28-
@"pushDate": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeStrong],
29-
@"payload": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy] };
26+
return @{ PFPushStatePropertyName(channels): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
27+
PFPushStatePropertyName(queryState): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
28+
PFPushStatePropertyName(expirationDate): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeStrong],
29+
PFPushStatePropertyName(expirationTimeInterval): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeStrong],
30+
PFPushStatePropertyName(pushDate): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeStrong],
31+
PFPushStatePropertyName(payload): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy] };
3032
}
3133

3234
///--------------------------------------
3335
#pragma mark - Init
3436
///--------------------------------------
3537

36-
- (instancetype)initWithState:(PFPushState *)state {
38+
- (instancetype)initWithState:(nullable PFPushState *)state {
3739
return [super initWithState:state];
3840
}
3941

40-
+ (instancetype)stateWithState:(PFPushState *)state {
42+
+ (instancetype)stateWithState:(nullable PFPushState *)state {
4143
return [super stateWithState:state];
4244
}
4345

4446
///--------------------------------------
4547
#pragma mark - NSCopying
4648
///--------------------------------------
4749

48-
- (void)setPushDate:(NSDate *)pushDate {
50+
- (void)setPushDate:(nullable NSDate *)pushDate {
4951
if (self.pushDate != pushDate) {
5052
NSTimeInterval interval = pushDate.timeIntervalSinceNow;
5153
PFParameterAssert(interval > 0, @"Can't set the scheduled push time in the past.");
@@ -58,16 +60,18 @@ - (void)setPushDate:(NSDate *)pushDate {
5860
#pragma mark - NSCopying
5961
///--------------------------------------
6062

61-
- (id)copyWithZone:(NSZone *)zone {
63+
- (id)copyWithZone:(nullable NSZone *)zone {
6264
return [[PFPushState allocWithZone:zone] initWithState:self];
6365
}
6466

6567
///--------------------------------------
6668
#pragma mark - NSMutableCopying
6769
///--------------------------------------
6870

69-
- (id)mutableCopyWithZone:(NSZone *)zone {
71+
- (id)mutableCopyWithZone:(nullable NSZone *)zone {
7072
return [[PFMutablePushState allocWithZone:zone] initWithState:self];
7173
}
7274

7375
@end
76+
77+
NS_ASSUME_NONNULL_END

Parse/Internal/Push/State/PFPushState_Private.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010
#import "PFPushState.h"
1111

12+
/**
13+
Returns NSString representation of a property.
14+
15+
@param NAME The name of the property.
16+
17+
@return NSString representation of a given property.
18+
*/
19+
#define PFPushStatePropertyName(NAME) @keypath(PFPushState, NAME)
20+
1221
NS_ASSUME_NONNULL_BEGIN
1322

1423
@interface PFPushState ()

Parse/Internal/Relation/State/PFMutableRelationState.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ @implementation PFMutableRelationState
2828
+ (NSDictionary *)propertyAttributes {
2929
NSMutableDictionary *parentAttributes = [[super propertyAttributes] mutableCopy];
3030

31-
parentAttributes[@"knownObjects"] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
31+
parentAttributes[PFRelationStatePropertyName(knownObjects)] = [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeMutableCopy];
3232

3333
return parentAttributes;
3434
}

Parse/Internal/Relation/State/PFRelationState.m

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ @implementation PFRelationState
1919
///--------------------------------------
2020

2121
+ (NSDictionary *)propertyAttributes {
22-
return @{
23-
@"parent": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeWeak],
24-
@"parentClassName": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
25-
@"parentObjectId": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
26-
@"targetClass": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
27-
@"knownObjects": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
28-
@"key": [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
29-
};
22+
return @{ PFRelationStatePropertyName(parent): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeWeak],
23+
PFRelationStatePropertyName(parentClassName): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
24+
PFRelationStatePropertyName(parentObjectId): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
25+
PFRelationStatePropertyName(targetClass): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
26+
PFRelationStatePropertyName(knownObjects): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy],
27+
PFRelationStatePropertyName(key): [PFPropertyAttributes attributesWithAssociationType:PFPropertyInfoAssociationTypeCopy] };
3028
}
3129

3230
///--------------------------------------

Parse/Internal/Relation/State/PFRelationState_Private.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
#import "PFRelationState.h"
1111

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

0 commit comments

Comments
 (0)