[AFHTTPClient init] should raise an exception
As discussed on #971, this will prevent anyone from accidentally calling init which results in undefined behaviour. http://developer.apple.com/library/ios/#documentation/general/conceptual/devpedia-cocoacore/MultipleInitializers.html
This commit is contained in:
parent
efb36aaa99
commit
0f608ec1ac
2 changed files with 10 additions and 0 deletions
|
|
@ -221,6 +221,12 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
|
|||
return [[self alloc] initWithBaseURL:url];
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"%@ Failed to call designated initializer. Invoke `initWithBaseURL:` instead.", NSStringFromClass([self class])]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (id)initWithBaseURL:(NSURL *)url {
|
||||
NSParameterAssert(url);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@
|
|||
|
||||
#pragma mark -
|
||||
|
||||
- (void)testInitRaisesException {
|
||||
expect(^{ (void)[[AFHTTPClient alloc] init]; }).to.raiseAny();
|
||||
}
|
||||
|
||||
- (void)testDefaultHeaders {
|
||||
[self.client setDefaultHeader:@"x-some-key" value:@"SomeValue"];
|
||||
expect([self.client defaultValueForHeader:@"x-some-key"]).to.equal(@"SomeValue");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue