Skip to content

Commit

Permalink
Merge pull request #3 from Wasappli/feature/swift_compatibility
Browse files Browse the repository at this point in the history
Swift compatibility
  • Loading branch information
ipodishima authored Aug 30, 2017
2 parents 09c3a2f + ccc4add commit 616abe6
Show file tree
Hide file tree
Showing 29 changed files with 248 additions and 235 deletions.
6 changes: 3 additions & 3 deletions Files/WABatchCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
*
* @param batchObject a batch object to enqueue
*/
- (void)addBatchObject:(WABatchObject *)batchObject;
- (void)addBatchObject:(WABatchObject *_Nonnull)batchObject;

/**
* Remove objects from cache store
*
* @param batchObjects the objects to remove
*/
- (void)removeBatchObjects:(NSArray <WABatchObject *>*)batchObjects;
- (void)removeBatchObjects:(NSArray <WABatchObject *>*_Nonnull)batchObjects;

/**
* Completely drop the database. Also resets the auto increment id
Expand All @@ -38,6 +38,6 @@
/**
* The batch objects on cache
*/
@property (nonatomic, readonly) NSArray *batchObjects;
@property (nonatomic, readonly) NSArray *_Nonnull batchObjects;

@end
6 changes: 3 additions & 3 deletions Files/WABatchManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
@interface WABatchManager : NSObject <WABatchManagerProtocol>

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Add a route describing the request which can be enqueued
*
* @param route the route allowed to be automatically batched if offline
*/
- (void)addRouteToBatchIfOffline:(WANetworkRoute *)route;
- (void)addRouteToBatchIfOffline:(WANetworkRoute *_Nonnull)route;

@end
30 changes: 15 additions & 15 deletions Files/WABatchManagerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* @param batchManager the batch manager triggering the event
* @param batchResponses an array of batch responses which contains the request, the response and the mapped object if the mapping is configured
*/
typedef void (^WABatchManagerSuccess)(id <WABatchManagerProtocol> batchManager, NSArray <WABatchResponse *> *batchResponses);
typedef void (^WABatchManagerSuccess)(_Nonnull id <WABatchManagerProtocol> batchManager, NSArray <WABatchResponse *> *_Nullable batchResponses);

/**
* A block called on failure
*
* @param batchManager the batch manager triggering the event
* @param request the batch request
* @param response the response from the batch request
* @param <WANRErrorProtocol>error the error
* @param error the error
*/
typedef void (^WABatchManagerFailure)(id <WABatchManagerProtocol> batchManager, WAObjectRequest *request, WAObjectResponse *response, id <WANRErrorProtocol>error);
typedef void (^WABatchManagerFailure)(_Nonnull id <WABatchManagerProtocol> batchManager, WAObjectRequest *_Nonnull request, WAObjectResponse *_Nullable response, _Nullable id <WANRErrorProtocol>error);

/**
This protocols defines the batch manager. The library has a default implementation `WABatchManager`.
Expand All @@ -44,7 +44,7 @@ typedef void (^WABatchManagerFailure)(id <WABatchManagerProtocol> batchManager,
*
* @return a batch manager
*/
- (instancetype)initWithBatchPath:(NSString *)batchPath limit:(NSUInteger)limit;
- (instancetype _Nonnull)initWithBatchPath:(NSString *_Nonnull)batchPath limit:(NSUInteger)limit;

/**
* @see `initWithBatchPath: limit`
Expand All @@ -54,7 +54,7 @@ typedef void (^WABatchManagerFailure)(id <WABatchManagerProtocol> batchManager,
*
* @return a batch manager
*/
+ (instancetype)batchManagerWithBatchPath:(NSString *)batchPath limit:(NSUInteger)limit;
+ (instancetype _Nonnull)batchManagerWithBatchPath:(NSString *_Nonnull)batchPath limit:(NSUInteger)limit;

// ———————————————————————
// Offline management
Expand All @@ -72,7 +72,7 @@ typedef void (^WABatchManagerFailure)(id <WABatchManagerProtocol> batchManager,
*
* @param completion a completion block called when the flush is complete.
*/
- (void)flushDataWithCompletion:(void(^)(BOOL success))completion;
- (void)flushDataWithCompletion:( void(^ _Nonnull )(BOOL success))completion;

/**
* Determine if a request can be enqueued or not. On `WABatchManager` implementation, you have to use `WANetworkRoute`
Expand All @@ -83,14 +83,14 @@ typedef void (^WABatchManagerFailure)(id <WABatchManagerProtocol> batchManager,
*
* @return YES if the request can be enqueued
*/
- (BOOL)canEnqueueOfflineRequest:(WAObjectRequest *)request withResponse:(WAObjectResponse *)response error:(id<WANRErrorProtocol>) error;
- (BOOL)canEnqueueOfflineRequest:(WAObjectRequest *_Nonnull)request withResponse:(WAObjectResponse *_Nullable)response error:(_Nullable id<WANRErrorProtocol>) error;

/**
* Enqueue for offline the request which cannot be triggered because the app is offline
*
* @param request the request to enqueue
*/
- (void)enqueueOfflineRequest:(WAObjectRequest *)request;
- (void)enqueueOfflineRequest:(WAObjectRequest *_Nonnull)request;

/**
* Reset the database and remove all saved requests
Expand All @@ -115,27 +115,27 @@ typedef void (^WABatchManagerFailure)(id <WABatchManagerProtocol> batchManager,
* @param successBlock a block called on success
* @param failureBlock a block called on failure
*/
- (void)sendBatchSession:(WABatchSession *)session successBlock:(WABatchManagerSuccess)successBlock failureBlock:(WABatchManagerFailure)failureBlock;
- (void)sendBatchSession:(WABatchSession *_Nonnull)session successBlock:(_Nullable WABatchManagerSuccess)successBlock failureBlock:(_Nullable WABatchManagerFailure)failureBlock;

/**
* A delegate for the batch. Used for communicating with the `WANetworkRoutingManager` to enqueue the request and map the responses
*/
@property (nonatomic, weak) id <WABatchManagerDelegate> delegate;
@property (nonatomic, weak) _Nullable id <WABatchManagerDelegate> delegate;

/**
* A block called on each offline batch session sent if success. Basically, you should call `neesdFlushing` to know if there are some pending offline batch objects to send.
*/
@property (nonatomic, copy) WABatchManagerSuccess offlineFlushSuccessBlock;
@property (nonatomic, copy) _Nullable WABatchManagerSuccess offlineFlushSuccessBlock;
/**
* A block called on offline batch if there is any error. Note that this is the `/batch` error, not the possible errors from the batch requests themselves.
*/
@property (nonatomic, copy) WABatchManagerFailure offlineFlushFailureBlock;
@property (nonatomic, copy) _Nullable WABatchManagerFailure offlineFlushFailureBlock;

@end

@protocol WABatchManagerDelegate <NSObject>

- (void)batchManager:(id<WABatchManagerProtocol>)batchManager haveBatchRequestToEnqueue:(WAObjectRequest *)objectRequest;
- (void)batchManager:(id<WABatchManagerProtocol>)batchManager haveBatchResponsesToProcess:(NSArray <WABatchResponse *>*)batchReponses;
- (void)batchManager:(_Nonnull id<WABatchManagerProtocol>)batchManager haveBatchRequestToEnqueue:(WAObjectRequest *_Nonnull)objectRequest;
- (void)batchManager:(_Nonnull id<WABatchManagerProtocol>)batchManager haveBatchResponsesToProcess:(NSArray <WABatchResponse *>*_Nonnull)batchReponses;

@end
@end
10 changes: 5 additions & 5 deletions Files/WABatchObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*/
@interface WABatchObject : NSObject <NSCoding>

@property (nonatomic, strong) NSNumber *batchID; // The batch ID
@property (nonatomic, strong) NSString *method; // The method (POST GET PUT ...)
@property (nonatomic, strong) NSString *uri; // The relative path (/items for http://someURL.com/items)
@property (nonatomic, strong) id parameters; // The parameters
@property (nonatomic, strong) id headers; // The headers for the specific request. Default is content type = application/json
@property (nonatomic, strong) NSNumber *_Nonnull batchID; // The batch ID
@property (nonatomic, strong) NSString *_Nonnull method; // The method (POST GET PUT ...)
@property (nonatomic, strong) NSString *_Nonnull uri; // The relative path (/items for http://someURL.com/items)
@property (nonatomic, strong) _Nullable id parameters; // The parameters
@property (nonatomic, strong) _Nullable id headers; // The headers for the specific request. Default is content type = application/json

@end
6 changes: 3 additions & 3 deletions Files/WABatchResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
@interface WABatchResponse : NSObject

@property (nonatomic, strong) WAObjectRequest *request;
@property (nonatomic, strong) WAObjectResponse *response;
@property (nonatomic, strong) NSArray *mappedObjects;
@property (nonatomic, strong) WAObjectRequest *_Nonnull request;
@property (nonatomic, strong) WAObjectResponse *_Nonnull response;
@property (nonatomic, strong) NSArray *_Nullable mappedObjects;

@end
6 changes: 3 additions & 3 deletions Files/WABatchSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
*
* @param objectRequest the request to enqueue in the session
*/
- (void)addRequest:(WAObjectRequest *)objectRequest;
- (void)addRequest:(WAObjectRequest *_Nonnull)objectRequest;

/**
* Same as adding a request, but you add a batch object instead. You have no reason to use this method. It is internally used in `WABatchManager` implementation.
*
* @param batchObject the batch objct to enqueue in the session
*/
- (void)addBatchObject:(WABatchObject *)batchObject;
- (void)addBatchObject:(WABatchObject *_Nonnull)batchObject;

/**
* An array of batch objects enqueued
*/
@property (nonatomic, readonly) NSArray<WABatchObject *> *batchObjects;
@property (nonatomic, readonly) NSArray<WABatchObject *> *_Nonnull batchObjects;

@end
16 changes: 8 additions & 8 deletions Files/WAMappingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

@interface WAMappingManager : NSObject <WAMappingManagerProtocol>

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Init the mapping manager with a store
Expand All @@ -24,7 +24,7 @@
*
* @return a fresh mapping manager
*/
- (instancetype)initWithStore:(id <WAStoreProtocol>)store NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithStore:(_Nonnull id <WAStoreProtocol>)store NS_DESIGNATED_INITIALIZER;

/**
* Create mapping manager with a store
Expand All @@ -33,23 +33,23 @@
*
* @return a fresh mapping manager
*/
+ (instancetype)mappingManagerWithStore:(id <WAStoreProtocol>)store;
+ (instancetype _Nonnull)mappingManagerWithStore:(_Nonnull id <WAStoreProtocol>)store;

/**
* Add a new response descriptor
*
* @param responseDescriptor a response descriptor
*/
- (void)addResponseDescriptor:(WAResponseDescriptor *)responseDescriptor;
- (void)addResponseDescriptor:(WAResponseDescriptor *_Nonnull)responseDescriptor;

/**
* Add a new request descriptor
*
* @param requestDescriptor a request descriptor
*/
- (void)addRequestDescriptor:(WARequestDescriptor *)requestDescriptor;
- (void)addRequestDescriptor:(WARequestDescriptor *_Nonnull)requestDescriptor;

@property (nonatomic, strong, readonly) NSArray<WAResponseDescriptor *> *responseDescriptors;
@property (nonatomic, strong, readonly) NSArray<WARequestDescriptor*> *requestDescriptors;
@property (nonatomic, strong, readonly) NSArray<WAResponseDescriptor *> *_Nonnull responseDescriptors;
@property (nonatomic, strong, readonly) NSArray<WARequestDescriptor*> *_Nonnull requestDescriptors;

@end
16 changes: 8 additions & 8 deletions Files/WAMappingManagerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@class WAObjectRequest, WAObjectResponse;

typedef void (^WAMappingManagerMappingCompletion)(NSArray *mappedObjects, NSError *error);
typedef id (^WAMappingManagerMappingBlock)(id value);
typedef void (^WAMappingManagerMappingCompletion)(NSArray *_Nullable mappedObjects, NSError *_Nullable error);
typedef _Nullable id (^WAMappingManagerMappingBlock)(id _Nonnull value);

@protocol WAMappingManagerProtocol <NSObject>

Expand All @@ -23,7 +23,7 @@ typedef id (^WAMappingManagerMappingBlock)(id value);
*
* @return YES if there is at least one response descriptor
*/
- (BOOL)canMapRequestResponse:(WAObjectRequest *)request;
- (BOOL)canMapRequestResponse:(WAObjectRequest *_Nonnull)request;

/**
* Map the response to managed objects using responses descriptors registered (there can be many)
Expand All @@ -32,7 +32,7 @@ typedef id (^WAMappingManagerMappingBlock)(id value);
* @param request the original request
* @param completion a block with an array of all mapped objects no matter the hierarchy
*/
- (void)mapResponse:(WAObjectResponse *)response fromRequest:(WAObjectRequest *)request withCompletion:(WAMappingManagerMappingCompletion)completion;
- (void)mapResponse:(WAObjectResponse *_Nonnull)response fromRequest:(WAObjectRequest *_Nonnull)request withCompletion:(_Nonnull WAMappingManagerMappingCompletion)completion;

/**
* Map an object to dictionary for the request
Expand All @@ -43,29 +43,29 @@ typedef id (^WAMappingManagerMappingBlock)(id value);
*
* @return a dictionary mapped with object properties from original mapping
*/
- (NSDictionary *)mapObject:(id)object forPath:(NSString *)path method:(WAObjectRequestMethod)method;
- (NSDictionary *_Nullable)mapObject:(_Nullable id)object forPath:(NSString *_Nullable)path method:(WAObjectRequestMethod)method;

/**
* Delete an object from store. This usually comes from a DELETE operation
*
* @param object the object to delete
*/
- (void)deleteObjectFromStore:(id)object fromRequest:(WAObjectRequest *)request;
- (void)deleteObjectFromStore:(_Nonnull id)object fromRequest:(WAObjectRequest *_Nonnull)request;

/**
* Add a default mapping block for a class. For example, you could have an API returning dates all with the same format. You can register the transformation once here.
*
* @param mappingBlock the mapping block called to transform the value
* @param destinationClass the destination class
*/
- (void)addDefaultMappingBlock:(WAMappingManagerMappingBlock)mappingBlock forDestinationClass:(Class)destinationClass;
- (void)addDefaultMappingBlock:(_Nonnull WAMappingManagerMappingBlock)mappingBlock forDestinationClass:(_Nonnull Class)destinationClass;

/**
* Add a reverse default mapping block for a class. For example, you could have an API returning dates all with the same format. You can register the transformation once here.
*
* @param reverseMappingBlock the reverse mapping block called to transform the value
* @param destinationClass the destination class
*/
- (void)addReverseDefaultMappingBlock:(WAMappingManagerMappingBlock)reverseMappingBlock forDestinationClass:(Class)destinationClass;
- (void)addReverseDefaultMappingBlock:(_Nonnull WAMappingManagerMappingBlock)reverseMappingBlock forDestinationClass:(_Nonnull Class)destinationClass;

@end
8 changes: 4 additions & 4 deletions Files/WANRErrorProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

@protocol WANRErrorProtocol <NSObject>

- (instancetype)initWithOriginalError:(NSError *)error response:(WAObjectResponse *)response;
- (instancetype _Nonnull)initWithOriginalError:(NSError *_Nullable)error response:(WAObjectResponse *_Nullable)response;

@property (nonatomic, strong, readonly) NSError *originalError;
@property (nonatomic, strong, readonly) NSError *finalError;
@property (nonatomic, strong, readonly) WAObjectResponse *response;
@property (nonatomic, strong, readonly) NSError *_Nullable originalError;
@property (nonatomic, strong, readonly) NSError *_Nullable finalError;
@property (nonatomic, strong, readonly) WAObjectResponse *_Nullable response;

@end
12 changes: 6 additions & 6 deletions Files/WANetworkRoute.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@interface WANetworkRoute : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Create a new route description to use on router
Expand All @@ -23,13 +23,13 @@
*
* @return a new route
*/
- (instancetype)initWithObjectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(WAObjectRequestMethod)method NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithObjectClass:(_Nullable Class)objectClass pathPattern:(NSString *_Nonnull)pathPattern method:(WAObjectRequestMethod)method NS_DESIGNATED_INITIALIZER;

// @see `initWithObjectClass: pathPattern: method:`
+ (instancetype)routeWithObjectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(WAObjectRequestMethod)method;
+ (instancetype _Nonnull)routeWithObjectClass:(_Nullable Class)objectClass pathPattern:(NSString *_Nonnull)pathPattern method:(WAObjectRequestMethod)method;

@property (nonatomic, strong, readonly) Class objectClass;
@property (nonatomic, strong, readonly) Class _Nullable objectClass;
@property (nonatomic, assign, readonly) WAObjectRequestMethod method;
@property (nonatomic, strong, readonly) NSString *pathPattern;
@property (nonatomic, strong, readonly) NSString *_Nonnull pathPattern;

@end
12 changes: 6 additions & 6 deletions Files/WANetworkRoutePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@interface WANetworkRoutePattern : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Init with a pattern like 'list/:itemID/extra'
Expand All @@ -20,7 +20,7 @@
*
* @return Return a fresh pattern matcher
*/
- (instancetype)initWithPattern:(NSString *)pattern NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithPattern:(NSString *_Nonnull)pattern NS_DESIGNATED_INITIALIZER;

/**
* Tests if a route matches the pattern
Expand All @@ -29,7 +29,7 @@
*
* @return YES if matches, NO if not
*/
- (BOOL)matchesRoute:(NSString *)route;
- (BOOL)matchesRoute:(NSString *_Nonnull)route;

/**
* Get the string path with values replaced from object properties
Expand All @@ -38,8 +38,8 @@
*
* @return A string from path pattern with values replaced
*/
- (NSString *)stringFromObject:(id)object;
- (NSString *_Nullable)stringFromObject:(_Nonnull id)object;

@end

FOUNDATION_EXTERN NSString * const WANetworkRoutePatternObjectPrefix;
FOUNDATION_EXTERN NSString * _Nonnull const WANetworkRoutePatternObjectPrefix;
Loading

0 comments on commit 616abe6

Please sign in to comment.