Skip to content

Cleanup assertions, convert to macros where possible. #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Parse/Internal/Query/Controller/PFCachedQueryController.m
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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