Enforcing 'this parameter must not be nil' by using NSCParameterAssert()

This commit is contained in:
Mattt Thompson 2012-10-05 10:09:13 -07:00
parent c830a82080
commit a2fc510f72
2 changed files with 14 additions and 7 deletions

View file

@ -131,7 +131,7 @@ typedef enum {
/**
Creates and initializes an `AFHTTPClient` object with the specified base URL.
@param url The base URL for the HTTP client. This argument must not be nil.
@param url The base URL for the HTTP client. This argument must not be `nil`.
@return The newly-initialized HTTP client
*/
@ -510,7 +510,7 @@ extern NSTimeInterval const kAFUploadStream3GSuggestedDelay;
/**
Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary.
@param fileURL The URL corresponding to the file whose content will be appended to the form.
@param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`.
@param name The name to be associated with the specified data. This parameter must not be `nil`.
@param error If an error occurs, upon return contains an `NSError` object that describes the problem.
@ -527,8 +527,8 @@ extern NSTimeInterval const kAFUploadStream3GSuggestedDelay;
@param data The data to be encoded and appended to the form data.
@param name The name to be associated with the specified data. This parameter must not be `nil`.
@param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
@param filename The filename to be associated with the specified data. This parameter must not be `nil`.
@param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
*/
- (void)appendPartWithFileData:(NSData *)data
name:(NSString *)name

View file

@ -231,14 +231,12 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
}
- (id)initWithBaseURL:(NSURL *)url {
NSCParameterAssert(url);
self = [super init];
if (!self) {
return nil;
}
if (!url) {
[NSException raise:@"-[AFHTTPClient initWithBaseURL:] nil URL" format:@"`url` must not be nil"];
}
// Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected
if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) {
@ -781,6 +779,9 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
name:(NSString *)name
error:(NSError * __autoreleasing *)error
{
NSCParameterAssert(fileURL);
NSCParameterAssert(name);
if (![fileURL isFileURL]) {
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey];
if (error != NULL) {
@ -819,6 +820,10 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
fileName:(NSString *)fileName
mimeType:(NSString *)mimeType
{
NSCParameterAssert(name);
NSCParameterAssert(fileName);
NSCParameterAssert(mimeType);
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
[mutableHeaders setValue:mimeType forKey:@"Content-Type"];
@ -829,6 +834,8 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
- (void)appendPartWithFormData:(NSData *)data
name:(NSString *)name
{
NSCParameterAssert(name);
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
[mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];