Skip to content

Commit

Permalink
Merge pull request #112 from button/pavel/111_registerHandlerClass_sw…
Browse files Browse the repository at this point in the history
…ift3_interface

#111 - registerHandlerClass:forRoute: interface is generated for Swift 3
  • Loading branch information
pavelpantus authored Sep 22, 2016
2 parents 6931ecf + 0cfaaac commit 384fa09
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ branches:
only:
master
before_install:
- gem install activesupport -N
- gem install slather --no-rdoc --no-ri --no-document --quiet
- gem i cocoapods --no-ri --no-rdoc
- bundle
- pod install
script:
- xctool test -workspace DeepLinkKit.xcworkspace -scheme ReceiverDemo -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
Expand Down
5 changes: 2 additions & 3 deletions DeepLinkKit/Router/DPLDeepLinkRouter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import Foundation;

@class DPLDeepLink;
@protocol DPLRouteHandler;
@class DPLDeepLink;


/**
Expand Down Expand Up @@ -48,7 +47,7 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error);
For example, you can register a class for a route as follows:
@code deepLinkRouter[@"table/book/:id"] = [MyBookingRouteHandler class]; @endcode
*/
- (void)registerHandlerClass:(Class <DPLRouteHandler>)handlerClass forRoute:(NSString *)route;
- (void)registerHandlerClass:(Class)handlerClass forRoute:(NSString *)route;


/**
Expand Down
4 changes: 2 additions & 2 deletions DeepLinkKit/Router/DPLDeepLinkRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ - (BOOL)applicationCanHandleDeepLinks {

#pragma mark - Registering Routes

- (void)registerHandlerClass:(Class <DPLRouteHandler>)handlerClass forRoute:(NSString *)route {
- (void)registerHandlerClass:(Class)handlerClass forRoute:(NSString *)route {

if (handlerClass && [route length]) {
if (handlerClass && [handlerClass isSubclassOfClass:[DPLRouteHandler class]] && [route length]) {
[self.routes addObject:route];
[self.blocksByRoute removeObjectForKey:route];
self.classesByRoute[route] = handlerClass;
Expand Down
10 changes: 10 additions & 0 deletions Tests/Router/DPLDeepLinkRouterSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@
expect(router[route]).to.equal([DPLRouteHandler class]);
});

it(@"registers a class for a route with registerHandlerClass:forRoute:", ^{
[router registerHandlerClass:[DPLRouteHandler class] forRoute:route];
expect(router[route]).to.equal([DPLRouteHandler class]);
});

it(@"does NOT register a class not conforming to DPLRouteHandler protocol", ^{
router[route] = [NSObject class];
expect(router[route]).to.beNil();
});

it(@"does NOT register not a subclass of DPLRouteHandler with registerHandlerClass:forRoute:", ^{
[router registerHandlerClass:[NSObject class] forRoute:route];
expect(router[route]).to.beNil();
});

it(@"does NOT register routes that are not strings", ^{
router[(id)@(0)] = [DPLRouteHandler class];
expect(router[route]).to.beNil();
Expand Down

0 comments on commit 384fa09

Please sign in to comment.