[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:
Kyle Fuller 2013-05-22 14:40:52 +01:00
parent efb36aaa99
commit 0f608ec1ac
2 changed files with 10 additions and 0 deletions

View file

@ -221,6 +221,12 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
return [[self alloc] initWithBaseURL:url]; 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 { - (id)initWithBaseURL:(NSURL *)url {
NSParameterAssert(url); NSParameterAssert(url);

View file

@ -35,6 +35,10 @@
#pragma mark - #pragma mark -
- (void)testInitRaisesException {
expect(^{ (void)[[AFHTTPClient alloc] init]; }).to.raiseAny();
}
- (void)testDefaultHeaders { - (void)testDefaultHeaders {
[self.client setDefaultHeader:@"x-some-key" value:@"SomeValue"]; [self.client setDefaultHeader:@"x-some-key" value:@"SomeValue"];
expect([self.client defaultValueForHeader:@"x-some-key"]).to.equal(@"SomeValue"); expect([self.client defaultValueForHeader:@"x-some-key"]).to.equal(@"SomeValue");