Skip to content

Commit

Permalink
Merge pull request #90 from JohnSundell/annotations
Browse files Browse the repository at this point in the history
Add nullability & generic type annotations to all classes
  • Loading branch information
rastersize committed Feb 7, 2016
2 parents 84ada9b + a1f2c56 commit bb78b7e
Show file tree
Hide file tree
Showing 41 changed files with 292 additions and 95 deletions.
4 changes: 4 additions & 0 deletions SPTDataLoader/NSDictionary+HeaderSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
@import Foundation;

NS_ASSUME_NONNULL_BEGIN

/**
* A category for calculating the size of a header represented by an NSDictionary
*/
Expand All @@ -31,3 +33,5 @@
@property (nonatomic, assign, readonly, getter = spt_byteSizeOfHeaders) NSInteger byteSizeOfHeaders;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions SPTDataLoader/NSDictionary+HeaderSize.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
#import "NSDictionary+HeaderSize.h"

NS_ASSUME_NONNULL_BEGIN

@implementation NSDictionary (HeaderSize)

- (NSInteger)spt_byteSizeOfHeaders
Expand All @@ -45,3 +47,5 @@ - (NSInteger)spt_byteSizeOfHeaders
}

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions SPTDataLoader/SPTDataLoader+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#import "SPTDataLoaderRequestResponseHandler.h"

NS_ASSUME_NONNULL_BEGIN

/**
* The private API for the data loader for internal use in the SPTDataLoader library
*/
Expand All @@ -34,3 +36,5 @@
+ (instancetype)dataLoaderWithRequestResponseHandlerDelegate:(id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate;

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions SPTDataLoader/SPTDataLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
#import "SPTDataLoaderDelegate.h"
#import "SPTDataLoaderResponse+Private.h"

NS_ASSUME_NONNULL_BEGIN

@interface SPTDataLoader ()

@property (nonatomic, strong) NSHashTable *cancellationTokens;
@property (nonatomic, strong) NSMutableArray *requests;
@property (nonatomic, strong) NSHashTable<id<SPTDataLoaderCancellationToken>> *cancellationTokens;
@property (nonatomic, strong) NSMutableArray<SPTDataLoaderRequest *> *requests;

@end

Expand Down Expand Up @@ -182,3 +184,5 @@ - (void)receivedInitialResponse:(SPTDataLoaderResponse *)response
}

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@

#import "SPTDataLoaderCancellationTokenFactory.h"

NS_ASSUME_NONNULL_BEGIN

/**
* The generic implementation for the cancellation token factory
*/
@interface SPTDataLoaderCancellationTokenFactoryImplementation : NSObject <SPTDataLoaderCancellationTokenFactory>

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#import "SPTDataLoaderCancellationTokenImplementation.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SPTDataLoaderCancellationTokenFactoryImplementation

#pragma mark SPTDataLoaderCancellationTokenFactory
Expand All @@ -34,3 +36,5 @@ @implementation SPTDataLoaderCancellationTokenFactoryImplementation
}

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion SPTDataLoader/SPTDataLoaderCancellationTokenImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#import "SPTDataLoaderCancellationToken.h"

NS_ASSUME_NONNULL_BEGIN

/**
* The implementation for the cancellation token API
*/
Expand All @@ -33,6 +35,8 @@
* @param cancelObject The object that will be cancelled
*/
+ (instancetype)cancellationTokenImplementationWithDelegate:(id<SPTDataLoaderCancellationTokenDelegate>)delegate
cancelObject:(id)cancelObject;
cancelObject:(nullable id)cancelObject;

@end

NS_ASSUME_NONNULL_END
10 changes: 7 additions & 3 deletions SPTDataLoader/SPTDataLoaderCancellationTokenImplementation.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
*/
#import "SPTDataLoaderCancellationTokenImplementation.h"

NS_ASSUME_NONNULL_BEGIN

@interface SPTDataLoaderCancellationTokenImplementation ()


@property (nonatomic, assign, readwrite, getter = isCancelled) BOOL cancelled;
@property (nonatomic, weak, readwrite) id<SPTDataLoaderCancellationTokenDelegate> delegate;

@end

Expand All @@ -32,12 +34,12 @@ @implementation SPTDataLoaderCancellationTokenImplementation
#pragma mark SPTDataLoaderCancellationTokenImplementation

+ (instancetype)cancellationTokenImplementationWithDelegate:(id<SPTDataLoaderCancellationTokenDelegate>)delegate
cancelObject:(id)cancelObject
cancelObject:(nullable id)cancelObject
{
return [[self alloc] initWithDelegate:delegate cancelObject:cancelObject];
}

- (instancetype)initWithDelegate:(id<SPTDataLoaderCancellationTokenDelegate>)delegate cancelObject:(id)cancelObject
- (instancetype)initWithDelegate:(id<SPTDataLoaderCancellationTokenDelegate>)delegate cancelObject:(nullable id)cancelObject
{
if (!(self = [super init])) {
return nil;
Expand Down Expand Up @@ -67,3 +69,5 @@ - (void)cancel
}

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions SPTDataLoader/SPTDataLoaderFactory+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
@protocol SPTDataLoaderRequestResponseHandlerDelegate;
@protocol SPTDataLoaderAuthoriser;

NS_ASSUME_NONNULL_BEGIN

/**
* The private API for the data loader factory for internal use in the SPTDataLoader library
*/
Expand All @@ -35,7 +37,9 @@
* @param requestResponseHandlerDelegate The private delegate to delegate request handling to
* @param authorisers An NSArray of SPTDataLoaderAuthoriser objects for supporting different forms of authorisation
*/
+ (instancetype)dataLoaderFactoryWithRequestResponseHandlerDelegate:(id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate
authorisers:(NSArray *)authorisers;
+ (instancetype)dataLoaderFactoryWithRequestResponseHandlerDelegate:(nullable id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate
authorisers:(nullable NSArray<id<SPTDataLoaderAuthoriser>> *)authorisers;

@end

NS_ASSUME_NONNULL_END
18 changes: 11 additions & 7 deletions SPTDataLoader/SPTDataLoaderFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
#import "SPTDataLoaderResponse+Private.h"
#import "SPTDataLoaderRequest+Private.h"

NS_ASSUME_NONNULL_BEGIN

@interface SPTDataLoaderFactory () <SPTDataLoaderRequestResponseHandlerDelegate, SPTDataLoaderAuthoriserDelegate>

@property (nonatomic, strong) NSMapTable *requestToRequestResponseHandler;
@property (nonatomic, strong) NSMapTable<SPTDataLoaderRequest *, id<SPTDataLoaderRequestResponseHandler>> *requestToRequestResponseHandler;
@property (nonatomic, strong, readwrite) dispatch_queue_t requestTimeoutQueue;

@end
Expand All @@ -39,14 +41,14 @@ @implementation SPTDataLoaderFactory

#pragma mark Private

+ (instancetype)dataLoaderFactoryWithRequestResponseHandlerDelegate:(id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate
authorisers:(NSArray *)authorisers
+ (instancetype)dataLoaderFactoryWithRequestResponseHandlerDelegate:(nullable id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate
authorisers:(nullable NSArray<id<SPTDataLoaderAuthoriser>> *)authorisers
{
return [[self alloc] initWithRequestResponseHandlerDelegate:requestResponseHandlerDelegate authorisers:authorisers];
}

- (instancetype)initWithRequestResponseHandlerDelegate:(id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate
authorisers:(NSArray *)authorisers
- (instancetype)initWithRequestResponseHandlerDelegate:(nullable id<SPTDataLoaderRequestResponseHandlerDelegate>)requestResponseHandlerDelegate
authorisers:(nullable NSArray<id<SPTDataLoaderAuthoriser>> *)authorisers
{
if (!(self = [super init])) {
return nil;
Expand Down Expand Up @@ -161,8 +163,8 @@ - (void)authoriseRequest:(SPTDataLoaderRequest *)request

#pragma mark SPTDataLoaderRequestResponseHandlerDelegate

- (id<SPTDataLoaderCancellationToken>)requestResponseHandler:(id<SPTDataLoaderRequestResponseHandler>)requestResponseHandler
performRequest:(SPTDataLoaderRequest *)request
- (nullable id<SPTDataLoaderCancellationToken>)requestResponseHandler:(id<SPTDataLoaderRequestResponseHandler>)requestResponseHandler
performRequest:(SPTDataLoaderRequest *)request
{
if (self.offline) {
request.cachePolicy = NSURLRequestReturnCacheDataDontLoad;
Expand Down Expand Up @@ -216,3 +218,5 @@ - (void)dataLoaderAuthoriser:(id<SPTDataLoaderAuthoriser>)dataLoaderAuthoriser
}

@end

NS_ASSUME_NONNULL_END
10 changes: 7 additions & 3 deletions SPTDataLoader/SPTDataLoaderRateLimiter.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

#import "SPTDataLoaderRequest.h"

NS_ASSUME_NONNULL_BEGIN

@interface SPTDataLoaderRateLimiter ()

@property (nonatomic, assign) double requestsPerSecond;

@property (nonatomic, strong) NSMutableDictionary *serviceEndpointRequestsPerSecond;
@property (nonatomic, strong) NSMutableDictionary *serviceEndpointLastExecution;
@property (nonatomic, strong) NSMutableDictionary *serviceEndpointRetryAt;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSNumber *> *serviceEndpointRequestsPerSecond;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSNumber *> *serviceEndpointLastExecution;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSNumber *> *serviceEndpointRetryAt;

@end

Expand Down Expand Up @@ -147,3 +149,5 @@ - (NSString *)serviceKeyFromURL:(NSURL *)URL
}

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions SPTDataLoader/SPTDataLoaderRequest+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

@protocol SPTDataLoaderCancellationToken;

NS_ASSUME_NONNULL_BEGIN

/**
* A private delegate API for the objects in the SPTDataLoader library to use
*/
Expand All @@ -42,3 +44,5 @@
@property (nonatomic, weak) id<SPTDataLoaderCancellationToken> cancellationToken;

@end

NS_ASSUME_NONNULL_END
12 changes: 8 additions & 4 deletions SPTDataLoader/SPTDataLoaderRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#import "SPTDataLoaderRequest+Private.h"

NS_ASSUME_NONNULL_BEGIN

NSString * const SPTDataLoaderRequestErrorDomain = @"com.spotify.dataloader.request";

static NSString * NSStringFromSPTDataLoaderRequestMethod(SPTDataLoaderRequestMethod requestMethod);
Expand All @@ -30,7 +32,7 @@ @interface SPTDataLoaderRequest ()

@property (nonatomic, assign, readwrite) int64_t uniqueIdentifier;

@property (nonatomic, strong) NSMutableDictionary *mutableHeaders;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *mutableHeaders;
@property (nonatomic, assign) BOOL retriedAuthorisation;
@property (nonatomic, weak) id<SPTDataLoaderCancellationToken> cancellationToken;

Expand All @@ -40,12 +42,12 @@ @implementation SPTDataLoaderRequest

#pragma mark SPTDataLoaderRequest

+ (instancetype)requestWithURL:(NSURL *)URL sourceIdentifier:(NSString *)sourceIdentifier
+ (instancetype)requestWithURL:(NSURL *)URL sourceIdentifier:(nullable NSString *)sourceIdentifier
{
return [[self alloc] initWithURL:URL sourceIdentifier:sourceIdentifier];
}

- (instancetype)initWithURL:(NSURL *)URL sourceIdentifier:(NSString *)sourceIdentifier
- (instancetype)initWithURL:(NSURL *)URL sourceIdentifier:(nullable NSString *)sourceIdentifier
{
static int64_t uniqueIdentifierBarrier = 0;

Expand Down Expand Up @@ -183,7 +185,7 @@ - (NSString *)debugDescription

#pragma mark NSCopying

- (id)copyWithZone:(NSZone *)zone
- (id)copyWithZone:(nullable NSZone *)zone
{
__typeof(self) copy = [self.class requestWithURL:self.URL sourceIdentifier:self.sourceIdentifier];
copy.maximumRetryCount = self.maximumRetryCount;
Expand Down Expand Up @@ -218,3 +220,5 @@ - (id)copyWithZone:(NSZone *)zone
case SPTDataLoaderRequestMethodPut: return SPTDataLoaderRequestPutMethodString;
}
}

NS_ASSUME_NONNULL_END
10 changes: 7 additions & 3 deletions SPTDataLoader/SPTDataLoaderRequestResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@protocol SPTDataLoaderCancellationToken;
@protocol SPTDataLoaderRequestResponseHandler;

NS_ASSUME_NONNULL_BEGIN

/**
* A private delegate API for the creator of SPTDataLoader to use for routing requests through a user authentication
* layer
Expand All @@ -37,8 +39,8 @@
* @param requestResponseHandler The object that can perform requests and responses
* @param request The object describing the request to perform
*/
- (id<SPTDataLoaderCancellationToken>)requestResponseHandler:(id<SPTDataLoaderRequestResponseHandler>)requestResponseHandler
performRequest:(SPTDataLoaderRequest *)request;
- (nullable id<SPTDataLoaderCancellationToken>)requestResponseHandler:(id<SPTDataLoaderRequestResponseHandler>)requestResponseHandler
performRequest:(SPTDataLoaderRequest *)request;

@optional

Expand Down Expand Up @@ -66,7 +68,7 @@
/**
* The object to delegate performing requests to
*/
@property (nonatomic, weak, readonly) id<SPTDataLoaderRequestResponseHandlerDelegate> requestResponseHandlerDelegate;
@property (nonatomic, weak, readonly, nullable) id<SPTDataLoaderRequestResponseHandlerDelegate> requestResponseHandlerDelegate;

/**
* Call when a response successfully completed
Expand Down Expand Up @@ -109,3 +111,5 @@
- (void)authoriseRequest:(SPTDataLoaderRequest *)request;

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion SPTDataLoader/SPTDataLoaderRequestTaskHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
@class SPTDataLoaderResponse;
@protocol SPTDataLoaderRequestResponseHandler;

NS_ASSUME_NONNULL_BEGIN

/**
* The handler for performing a URL session task and forwarding the requests to relevant request response handler
*/
Expand Down Expand Up @@ -65,7 +67,7 @@
* Tell the operation the URL session has completed the request
* @param error An optional error to use if the request was not completed successfully
*/
- (SPTDataLoaderResponse *)completeWithError:(NSError *)error;
- (SPTDataLoaderResponse *)completeWithError:(nullable NSError *)error;
/**
* Gets called whenever the original request was redirected.
* Returns YES to allow redirect, NO to block it.
Expand All @@ -77,3 +79,5 @@
- (void)start;

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions SPTDataLoader/SPTDataLoaderRequestTaskHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#import "SPTDataLoaderExponentialTimer.h"

NS_ASSUME_NONNULL_BEGIN

static NSUInteger const SPTDataLoaderRequestTaskHandlerMaxRedirects = 10;

@interface SPTDataLoaderRequestTaskHandler ()
Expand All @@ -37,7 +39,7 @@ @interface SPTDataLoaderRequestTaskHandler ()
@property (nonatomic, strong) SPTDataLoaderRateLimiter *rateLimiter;

@property (nonatomic, strong) SPTDataLoaderResponse *response;
@property (nonatomic, strong) NSMutableData *receivedData;
@property (nonatomic, strong, nullable) NSMutableData *receivedData;
@property (nonatomic, assign) CFAbsoluteTime absoluteStartTime;
@property (nonatomic, assign) NSUInteger retryCount;
@property (nonatomic, assign) NSUInteger waitCount;
Expand Down Expand Up @@ -110,7 +112,7 @@ - (void)receiveData:(NSData *)data
}];
}

- (SPTDataLoaderResponse *)completeWithError:(NSError *)error
- (SPTDataLoaderResponse *)completeWithError:(nullable NSError *)error
{
id<SPTDataLoaderRequestResponseHandler> requestResponseHandler = self.requestResponseHandler;
if (!self.response) {
Expand Down Expand Up @@ -238,3 +240,5 @@ - (void)dealloc
}

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit bb78b7e

Please sign in to comment.