Zuikyo / ZIKRouter

Interface-oriented router for discovering modules, and injecting dependencies with protocol in Objective-C and Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZIKROUTER_CHECK 在 DEBUG 下总是崩溃, 我检查了都遵守了

manajay opened this issue · comments

+ (void)registerViewProtocol:(Protocol *)viewProtocol {
    NSAssert(!ZIKViewRouteRegistry.registrationFinished, @"Only register in +registerRoutableDestination.");
#if ZIKROUTER_CHECK
    NSAssert1(protocol_conformsToProtocol(viewProtocol, @protocol(ZIKViewRoutable)), @"%@ should conforms to ZIKViewRoutable in DEBUG mode for safety checking", NSStringFromProtocol(viewProtocol));
#endif
    [ZIKViewRouteRegistry registerDestinationProtocol:viewProtocol router:self];
}

.h 文件

#import "ZIKViperRouter.h"
#import <ZIKRouter/ZIKViewRoute.h>

#import <Foundation/Foundation.h>

@interface LSRecommendListWireFrame : ZIKViewRouter <ZIKViperRouter>
@end

#import "ZIKViewRouter+ZIKViper.h"
#import "ZIKViperViewPrivate.h"
#import <ZIKRouter/ZIKRouter.h>
#import <ZIKRouter/ZIKRouterInternal.h>

#import "LSRecommendListWireFrame.h"
#import "LSRecommendListInteractor.h"
#import "LSRecommendListPresenter.h"
#import "LSRecommendListController.h"

#import "LSRemoteCourseDataManager.h"
#import "LSDeviceClock.h"
#import "LSRouterConst.h"
#import "LSRecommendListViewInterface.h"

@interface LSRecommendListController (LSRecommendListWireFrame) <ZIKRoutableView>
@end
@implementation LSRecommendListController (LSRecommendListWireFrame)
@end

@interface LSRecommendListWireFrame ()

@end

@implementation LSRecommendListWireFrame

+ (void)registerRoutableDestination {
    [self registerView:[LSRecommendListController class]];
    [self registerViewProtocol:ZIKRoutable(LSRecommendListViewInterface)];
    [self registerIdentifier:HomeMatchSymbol];
}

- (UIViewController *)destinationWithConfiguration:(ZIKViewRouteConfiguration *)configuration {
    LSRecommendListController *listViewController = [[LSRecommendListController alloc] init];
    return listViewController;
}

- (BOOL)destinationFromExternalPrepared:(id)destination {
    NSParameterAssert([destination isKindOfClass:[LSRecommendListController class]]);
    NSParameterAssert([destination conformsToProtocol:@protocol(ZIKViperViewPrivate)]);
    if (![ZIKViewRouter isViperAssembledForView:destination]) {
        return NO;
    }
    return YES;
}

- (void)prepareDestination:(id)destination configuration:(__kindof ZIKViewRouteConfiguration *)configuration {
    NSParameterAssert([destination isKindOfClass:[LSRecommendListController class]]);
    NSParameterAssert([destination conformsToProtocol:@protocol(ZIKViperViewPrivate)]);
    if (![self isViperAssembled]) {
        [self assembleViper];
    } else {
        [self attachRouter];
    }
}

#pragma mark Viper assembly

- (void)assembleViper {
    id<ZIKViperViewPrivate> view = self.destination;
    NSAssert(view, @"Can't assemble viper when view is nil");
    
    LSRemoteCourseDataManager *dataManager = [[LSRemoteCourseDataManager alloc] init];
    LSDeviceClock *clock = [[LSDeviceClock alloc] init];
    
    LSRecommendListPresenter *presenter = [[LSRecommendListPresenter alloc] init];
    LSRecommendListInteractor *interactor = [[LSRecommendListInteractor alloc] initWithRemoteDataManager:dataManager clock:clock];
    interactor.output = presenter;
    
    [self assembleViperForView:view
                     presenter:(id<ZIKViperPresenterPrivate>)presenter
                    interactor:interactor];
}

- (void)attachRouter {
    id<ZIKViperViewPrivate> view = self.destination;
    NSAssert(view, @"Can't assemble viper when view is nil");
    [self attachRouterForView:view];
}

#pragma mark AOP

+ (void)router:(ZIKViewRouter *)router willPerformRouteOnDestination:(id)destination fromSource:(id)source {
    NSAssert([ZIKViewRouter isViperAssembledForView:destination], @"Viper should be assembled");
}


@end

协议

#import <Foundation/Foundation.h>
#import <ZIKRouter/ZIKRouter.h>

@protocol LSRecommendListViewInterface <NSObject>
@end

这个怎么回事

commented

LSRecommendListViewInterface should inherit from ZIKViewRoutable:

@protocol LSRecommendListViewInterface <NSObject, ZIKViewRoutable>
@end
commented

Read RoutableDeclaration for more detail.

thanks a lot , it fixs