From 0856ed3307c66666e851a74b64470d018a58569e Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Fri, 14 Aug 2015 17:52:21 -0700 Subject: [PATCH] Remove all usages of NSAssert. --- .../Controller/PFCachedQueryController.m | 2 +- Parse/PFGeoPoint.m | 21 +++++-------- Parse/PFObject.m | 4 +-- Parse/PFRole.h | 2 +- Parse/PFRole.m | 31 +++++++------------ 5 files changed, 23 insertions(+), 37 deletions(-) diff --git a/Parse/Internal/Query/Controller/PFCachedQueryController.m b/Parse/Internal/Query/Controller/PFCachedQueryController.m index b9529e23d..d89a9280e 100644 --- a/Parse/Internal/Query/Controller/PFCachedQueryController.m +++ b/Parse/Internal/Query/Controller/PFCachedQueryController.m @@ -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); diff --git a/Parse/PFGeoPoint.m b/Parse/PFGeoPoint.m index 4e7dbc5ed..9f9cf43f3 100644 --- a/Parse/PFGeoPoint.m +++ b/Parse/PFGeoPoint.m @@ -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 { diff --git a/Parse/PFObject.m b/Parse/PFObject.m index c45b14a1c..5117b2ccf 100644 --- a/Parse/PFObject.m +++ b/Parse/PFObject.m @@ -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)self parseClassName] predicate:predicate]; } diff --git a/Parse/PFRole.h b/Parse/PFRole.h index d188990b8..a406b291f 100644 --- a/Parse/PFRole.h +++ b/Parse/PFRole.h @@ -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 +@interface PFRole : PFObject ///-------------------------------------- /// @name Creating a New Role diff --git a/Parse/PFRole.m b/Parse/PFRole.m index bc797ca88..bceec7753 100644 --- a/Parse/PFRole.m +++ b/Parse/PFRole.m @@ -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]; @@ -50,11 +52,11 @@ + (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)]; } ///-------------------------------------- @@ -62,28 +64,17 @@ - (PFRelation *)users { ///-------------------------------------- - (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]; }