Skip to content

Commit

Permalink
Added an initializer with delegate
Browse files Browse the repository at this point in the history
Since the init method calls the "login" method,
there can be cases where the login completes before
the delegate is set via the property. In this case,
the caller would not know that the login completed
  • Loading branch information
JanC committed Mar 3, 2016
1 parent 0509eac commit 356da1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions OROpenSubtitleDownloader.h
Expand Up @@ -38,6 +38,9 @@ typedef enum {
/// Use a custom user agent
- (OROpenSubtitleDownloader *)initWithUserAgent:(NSString *)userAgent;

/// Use a custom user agent
- (OROpenSubtitleDownloader *)initWithUserAgent:(NSString *)userAgent delegate:(id<OROpenSubtitleDownloaderDelegate>) delegate NS_DESIGNATED_INITIALIZER;

/// The object that recieves notifications for new subtitles
@property (nonatomic, weak) NSObject <OROpenSubtitleDownloaderDelegate> *delegate;

Expand Down
9 changes: 7 additions & 2 deletions OROpenSubtitleDownloader.m
Expand Up @@ -32,14 +32,19 @@ @implementation OROpenSubtitleDownloader
#pragma mark Init

- (OROpenSubtitleDownloader *)init {
return [self initWithUserAgent:[self generateUserAgent]];
return [self initWithUserAgent:[self generateUserAgent] delegate:nil];
}

- (OROpenSubtitleDownloader *)initWithUserAgent:(NSString *)userAgent {
return [self initWithUserAgent:userAgent delegate:nil];
}

- (OROpenSubtitleDownloader *)initWithUserAgent:(NSString *)userAgent delegate:(id<OROpenSubtitleDownloaderDelegate>) delegate
{
self = [super init];
if (!self) return nil;


_delegate = delegate;
_userAgent = userAgent;
_blockResponses = [NSMutableDictionary dictionary];
_state = OROpenSubtitleStateLoggingIn;
Expand Down

0 comments on commit 356da1a

Please sign in to comment.