Skip to content

Commit b167a9f

Browse files
committed
Remove all usages of NSAssert.
1 parent 17c5dc7 commit b167a9f

File tree

5 files changed

+23
-37
lines changed

5 files changed

+23
-37
lines changed

Parse/Internal/Query/Controller/PFCachedQueryController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
112112
}
113113
break;
114114
case kPFCachePolicyCacheThenNetwork:
115-
PFConsistencyAssert(NO, @"kPFCachePolicyCacheThenNetwork is not implmented as a runner.");
115+
PFConsistencyAssert(NO, @"kPFCachePolicyCacheThenNetwork is not implemented as a runner.");
116116
break;
117117
default:
118118
PFConsistencyAssert(NO, @"Unrecognized cache policy: %d", queryState.cachePolicy);

Parse/PFGeoPoint.m

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,16 @@ + (void)geoPointForCurrentLocationInBackground:(PFGeoPointResultBlock)resultBloc
5858
#pragma mark - Accessors
5959
///--------------------------------------
6060

61-
- (void)setLatitude:(double)newLatitude {
62-
// Restrictions for mongo ranges (exclusive at high end).
63-
if (newLatitude >= 90.0 || newLatitude < -90.0) {
64-
[NSException raise:NSInvalidArgumentException
65-
format:@"latitude out of range (expect [-90.0, 90.0): %f", newLatitude];
66-
}
67-
_latitude = newLatitude;
61+
- (void)setLatitude:(double)latitude {
62+
PFParameterAssert(latitude >= -90.0 && latitude <= 90.0,
63+
@"`latitude` is out of range [-90.0, 90.0]: %f", latitude);
64+
_latitude = latitude;
6865
}
6966

70-
- (void)setLongitude:(double)newLongitude {
71-
if (newLongitude >= 180.0 || newLongitude < -180.0) {
72-
[NSException raise:NSInvalidArgumentException
73-
format:@"longitude out of range (expect [-180.0, 180.0): %f", newLongitude];
74-
}
75-
_longitude = newLongitude;
67+
- (void)setLongitude:(double)longitude {
68+
PFParameterAssert(longitude >= -180.0 && longitude <= 180.0,
69+
@"`longitude` is out of range [-180.0, 180.0]: %f", longitude);
70+
_longitude = longitude;
7671
}
7772

7873
- (double)distanceInRadiansTo:(PFGeoPoint *)point {

Parse/PFObject.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,8 +1962,8 @@ + (PFQuery *)query {
19621962
}
19631963

19641964
+ (PFQuery *)queryWithPredicate:(NSPredicate *)predicate {
1965-
NSAssert([self conformsToProtocol:@protocol(PFSubclassing)],
1966-
@"+[PFObject queryWithPredicate:] can only be called on subclasses conforming to PFSubclassing.");
1965+
PFConsistencyAssert([self conformsToProtocol:@protocol(PFSubclassing)],
1966+
@"+[PFObject queryWithPredicate:] can only be called on subclasses conforming to PFSubclassing.");
19671967
[PFObject assertSubclassIsRegistered:[self class]];
19681968
return [PFQuery queryWithClassName:[(id<PFSubclassing>)self parseClassName] predicate:predicate];
19691969
}

Parse/PFRole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PF_ASSUME_NONNULL_BEGIN
3030
3131
Roles must have a name (which cannot be changed after creation of the role), and must specify an ACL.
3232
*/
33-
@interface PFRole : PFObject<PFSubclassing>
33+
@interface PFRole : PFObject <PFSubclassing>
3434

3535
///--------------------------------------
3636
/// @name Creating a New Role

Parse/PFRole.m

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
@implementation PFRole
2020

21-
#pragma mark Creating a New Role
21+
///--------------------------------------
22+
#pragma mark - Init
23+
///--------------------------------------
2224

2325
- (instancetype)initWithName:(NSString *)name {
2426
return [self initWithName:name acl:nil];
@@ -50,40 +52,29 @@ + (instancetype)roleWithName:(NSString *)name acl:(PFACL *)acl {
5052

5153
// Dynamic synthesizers would use objectForKey, not relationForKey
5254
- (PFRelation *)roles {
53-
return [self relationForKey:@"roles"];
55+
return [self relationForKey:@keypath(PFRole, roles)];
5456
}
5557

5658
- (PFRelation *)users {
57-
return [self relationForKey:@"users"];
59+
return [self relationForKey:@keypath(PFRole, users)];
5860
}
5961

6062
///--------------------------------------
6163
#pragma mark - PFObject Overrides
6264
///--------------------------------------
6365

6466
- (void)setObject:(id)object forKey:(NSString *)key {
65-
if ([@"name" isEqualToString:key]) {
66-
if (self.objectId) {
67-
[NSException raise:NSInternalInconsistencyException
68-
format:@"A role's name can only be set before it has been saved."];
69-
}
70-
if (![object isKindOfClass:[NSString class]]) {
71-
[NSException raise:NSInvalidArgumentException
72-
format:@"A role's name must be an NSString."];
73-
}
74-
if ([object rangeOfString:@"^[0-9a-zA-Z_\\- ]+$" options:NSRegularExpressionSearch].location == NSNotFound) {
75-
[NSException raise:NSInvalidArgumentException
76-
format:@"A role's name can only contain alphanumeric characters, _, -, and spaces."];
77-
}
67+
if ([key isEqualToString:@keypath(PFRole, name)]) {
68+
PFConsistencyAssert(self.objectId, @"A role's name can only be set before it has been saved.");
69+
PFConsistencyAssert([object isKindOfClass:[NSString class]], @"A role's name must be an NSString.");
70+
PFConsistencyAssert([object rangeOfString:@"^[0-9a-zA-Z_\\- ]+$" options:NSRegularExpressionSearch].location != NSNotFound,
71+
@"A role's name can only contain alphanumeric characters, _, -, and spaces.");
7872
}
7973
[super setObject:object forKey:key];
8074
}
8175

8276
- (BFTask *)saveInBackground {
83-
if (!self.objectId && !self.name) {
84-
[NSException raise:NSInternalInconsistencyException
85-
format:@"New roles must specify a name."];
86-
}
77+
PFConsistencyAssert(!self.objectId || self.name, @"New roles must specify a name.");
8778
return [super saveInBackground];
8879
}
8980

0 commit comments

Comments
 (0)