Skip to content

Commit

Permalink
Remove all usages of NSAssert.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko committed Aug 17, 2015
1 parent 4e5e507 commit 0856ed3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Parse/Internal/Query/Controller/PFCachedQueryController.m
Expand Up @@ -112,7 +112,7 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
}
break;
case kPFCachePolicyCacheThenNetwork:
PFConsistencyAssert(NO, @"kPFCachePolicyCacheThenNetwork is not implmented as a runner.");
PFConsistencyAssert(NO, @"kPFCachePolicyCacheThenNetwork is not implemented as a runner.");
break;
default:
PFConsistencyAssert(NO, @"Unrecognized cache policy: %d", queryState.cachePolicy);
Expand Down
21 changes: 8 additions & 13 deletions Parse/PFGeoPoint.m
Expand Up @@ -58,21 +58,16 @@ + (void)geoPointForCurrentLocationInBackground:(PFGeoPointResultBlock)resultBloc
#pragma mark - Accessors
///--------------------------------------

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

- (void)setLongitude:(double)newLongitude {
if (newLongitude >= 180.0 || newLongitude < -180.0) {
[NSException raise:NSInvalidArgumentException
format:@"longitude out of range (expect [-180.0, 180.0): %f", newLongitude];
}
_longitude = newLongitude;
- (void)setLongitude:(double)longitude {
PFParameterAssert(longitude >= -180.0 && longitude <= 180.0,
@"`longitude` is out of range [-180.0, 180.0]: %f", longitude);
_longitude = longitude;
}

- (double)distanceInRadiansTo:(PFGeoPoint *)point {
Expand Down
4 changes: 2 additions & 2 deletions Parse/PFObject.m
Expand Up @@ -1962,8 +1962,8 @@ + (PFQuery *)query {
}

+ (PFQuery *)queryWithPredicate:(NSPredicate *)predicate {
NSAssert([self conformsToProtocol:@protocol(PFSubclassing)],
@"+[PFObject queryWithPredicate:] can only be called on subclasses conforming to PFSubclassing.");
PFConsistencyAssert([self conformsToProtocol:@protocol(PFSubclassing)],
@"+[PFObject queryWithPredicate:] can only be called on subclasses conforming to PFSubclassing.");
[PFObject assertSubclassIsRegistered:[self class]];
return [PFQuery queryWithClassName:[(id<PFSubclassing>)self parseClassName] predicate:predicate];
}
Expand Down
2 changes: 1 addition & 1 deletion Parse/PFRole.h
Expand Up @@ -30,7 +30,7 @@ PF_ASSUME_NONNULL_BEGIN
Roles must have a name (which cannot be changed after creation of the role), and must specify an ACL.
*/
@interface PFRole : PFObject<PFSubclassing>
@interface PFRole : PFObject <PFSubclassing>

///--------------------------------------
/// @name Creating a New Role
Expand Down
31 changes: 11 additions & 20 deletions Parse/PFRole.m
Expand Up @@ -18,7 +18,9 @@

@implementation PFRole

#pragma mark Creating a New Role
///--------------------------------------
#pragma mark - Init
///--------------------------------------

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

// Dynamic synthesizers would use objectForKey, not relationForKey
- (PFRelation *)roles {
return [self relationForKey:@"roles"];
return [self relationForKey:@keypath(PFRole, roles)];
}

- (PFRelation *)users {
return [self relationForKey:@"users"];
return [self relationForKey:@keypath(PFRole, users)];
}

///--------------------------------------
#pragma mark - PFObject Overrides
///--------------------------------------

- (void)setObject:(id)object forKey:(NSString *)key {
if ([@"name" isEqualToString:key]) {
if (self.objectId) {
[NSException raise:NSInternalInconsistencyException
format:@"A role's name can only be set before it has been saved."];
}
if (![object isKindOfClass:[NSString class]]) {
[NSException raise:NSInvalidArgumentException
format:@"A role's name must be an NSString."];
}
if ([object rangeOfString:@"^[0-9a-zA-Z_\\- ]+$" options:NSRegularExpressionSearch].location == NSNotFound) {
[NSException raise:NSInvalidArgumentException
format:@"A role's name can only contain alphanumeric characters, _, -, and spaces."];
}
if ([key isEqualToString:@keypath(PFRole, name)]) {
PFConsistencyAssert(!self.objectId, @"A role's name can only be set before it has been saved.");
PFParameterAssert([object isKindOfClass:[NSString class]], @"A role's name must be an NSString.");
PFParameterAssert([object rangeOfString:@"^[0-9a-zA-Z_\\- ]+$" options:NSRegularExpressionSearch].location != NSNotFound,
@"A role's name can only contain alphanumeric characters, _, -, and spaces.");
}
[super setObject:object forKey:key];
}

- (BFTask *)saveInBackground {
if (!self.objectId && !self.name) {
[NSException raise:NSInternalInconsistencyException
format:@"New roles must specify a name."];
}
PFConsistencyAssert(self.objectId || self.name, @"New roles must specify a name.");
return [super saveInBackground];
}

Expand Down

0 comments on commit 0856ed3

Please sign in to comment.