Giter Site home page Giter Site logo

zuikyo / zikrouter Goto Github PK

View Code? Open in Web Editor NEW
655.0 655.0 115.0 4.57 MB

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

License: MIT License

Objective-C 70.90% Ruby 0.39% Swift 27.46% C 0.33% C++ 0.80% Objective-C++ 0.13%
dependency-injection interface-oriented ios modular protocol-oriented router swift

zikrouter's People

Contributors

zuikyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zikrouter's Issues

ZIKViewRouter.m:2112 Assert 错误

在 WKWebView 中的输入框输入表情之后,收起键盘出现闪退

*** Assertion failure in -[UIKeyboardMediaServiceRemoteViewController willMoveToParentViewController:]
ZIKRouter/ZIKRouter/ViewRouter/ZIKViewRouter.m:2112

"0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350",
"1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48",
"2   CoreFoundation                      0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88",
"3   Foundation                          0x00007fff256e9b51 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:descript
"4   ZIKRouter                           0x000000010f6f46df -[ZIKViewRouter ZIKViewRouter_hook_willMoveToParentViewController:] + 399"
"5   UIKitCore                           0x00007fff47b2cb4c -[UIKeyboardMediaController releaseRecentlyUsedMediaViewIfNeeded] + 46",
"6   UIKitCore                           0x00007fff47e96539 -[UIKeyboardImpl setDelegate:force:] + 4931",
"7   UIKitCore                           0x00007fff47b56c12 -[UIInputResponderController _reloadInputViewsForKeyWindowSceneResponder:]
"8   UIKitCore                           0x00007fff47b563b3 -[UIInputResponderController _reloadInputViewsForResponder:] + 144",
"9   UIKitCore                           0x00007fff480c4c8b -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 133",
"10  WebKit                              0x00007fff2d46821b -[WKContentView(WKInteraction) _hideKeyboard] + 106",
"11  WebKit                              0x00007fff2d468c54 -[WKContentView(WKInteraction) _elementDidBlur] + 296",
"12  WebKit                              0x00007fff2cf4582e _ZN3IPC18MessageReceiverMap15dispatchMessageERNS_10ConnectionERNS_7Decoder
"13  WebKit                              0x00007fff2d190448 _ZN6WebKit15WebProcessProxy17didReceiveMessageERN3IPC10ConnectionERNS1_7De
"14  WebKit                              0x00007fff2cf31802 _ZN3IPC10Connection15dispatchMessageENSt3__110unique_ptrINS_7DecoderENS1_1
"15  WebKit                              0x00007fff2cf345a4 _ZN3IPC10Connection24dispatchIncomingMessagesEv + 408",
"16  JavaScriptCore                      0x00007fff268a11f4 _ZN3WTF7RunLoop11performWorkEv + 228",
"17  JavaScriptCore                      0x00007fff268a1482 _ZN3WTF7RunLoop11performWorkEPv + 34",
"18  CoreFoundation                      0x00007fff23bd4471 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17",
"19  CoreFoundation                      0x00007fff23bd439c __CFRunLoopDoSource0 + 76",
"20  CoreFoundation                      0x00007fff23bd3b74 __CFRunLoopDoSources0 + 180",
"21  CoreFoundation                      0x00007fff23bce87f __CFRunLoopRun + 1263",
"22  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438",
"23  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65",
"24  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621",
"25  HuoBan_DEBUG                        0x000000010bc7e300 main + 112",
"26  libdyld.dylib                       0x00007fff5227ec25 start + 1"

Demo写的太乱了

各种功能杂糅到一起,没有一个统一的头文件,比如ZIKRouterToView 引用ZIKRouter 找不到,竟然再另外一个分类里

Compiler error on ZRouter under xCode 10.1 swift 4

"_ZIKRouteActionPerformRoute", referenced from:
closure #1 (A) -> () in ZRouter.ViewRouterType.perform(path: ZRouter.ViewRoutePath, completion: (Swift.Bool, A?, __C.ZIKRouteAction, Swift.Error?) -> ()) -> ZRouter.ViewRouter<A, B>? in ViewRouter.o
closure #1 (A) -> () in ZRouter.ViewRouter.performRoute(completion: (Swift.Bool, A?, __C.ZIKRouteAction, Swift.Error?) -> ()) -> () in ViewRouter.o
closure #1 (A) -> () in ZRouter.ServiceRouterType.perform(completion: (Swift.Bool, A?, __C.ZIKRouteAction, Swift.Error?) -> ()) -> ZRouter.ServiceRouter<A, B>? in ServiceRouter.o
closure #1 (A) -> () in ZRouter.ServiceRouter.performRoute(completion: (Swift.Bool, A?, __C.ZIKRouteAction, Swift.Error?) -> ()) -> () in ServiceRouter.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

'The router (XMDModulesViewRouter) doesn't support makeDestination'

请问一下这个具体是什么原因, 找了挺久的, 大神帮我看看
2018-09-27 22:38:54.110016+0800 iOS-More[56319:8936026] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The router (XMDModulesViewRouter) doesn't support makeDestination'
*** First throw call stack:
(
0 CoreFoundation 0x000000010abbf29b __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010a157735 objc_exception_throw + 48
2 CoreFoundation 0x000000010abbf022 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000109b5bb47 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 ZIKRouter 0x00000001099d27c6 +[ZIKRouter makeDestinationWithConfiguring:] + 694
5 ZIKRouter 0x0000000109a013f5 +[ZIKViewRouter makeDestinationWithConfiguring:] + 517

还有一个疑问: 界面路由 与 界面模块路由, 其实两者之间的区别, 除了模块解耦, 那项目中, 具体说如何选用, 打个比方, 一个 tarbar 可以说更对应一个 界面模块路由吧?

内存泄露问题 ,有两个场景

1. 侧滑退出, 没有直接调用 removeRouter , 导致控制器释放, 但是 presenter 之类的没有释放

2. 主要控制器 添加子控制器,的视图, removeRouter 时 只移除 主控制器的, 导致子控制器的控制器以及 presenter 之类的无法释放

zix_checkMemoryLeak 在线程 com.zuik.router.object_leak_check_queue 中的逻辑导致卡顿/崩溃

在 DEBUG 模式下 , zix_checkMemoryLeak 在线程 com.zuik.router.object_leak_check_queue 中触发 - (NSString *)description 方法, 在该方法中, 如果调用了一些 UI 上的行为, 导致卡顿, 如图:
bug1
bug4
bug2
bug3
分别调用 UITableView 和 UIScrollView 的一些必须在 主线程 中操作的属性.
问题:

  1. 是否可以关闭zix_checkMemoryLeak, 影响如何?
  2. 是否可以在不关闭的前提下, 有其他解决方案? 暂时是在这几处加上了主线程调用, 但是因为也是第三方库, 希望尽量不修改到其代码.

___cxa_demangle ld: symbol(s) not found

Undefined symbols for architecture arm64:
"___cxa_demangle", referenced from:
-[NSString(Demangle) demangledAsCPP] in libZIKRouter.a(NSString+Demangle.o)
"std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >::__init(char const*, unsigned long)", referenced from:
_demangleSymbolAsString(char const*, unsigned long, DemangleOptions const&) in libZIKRouter.a(NSString+Demangle.o)
"std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >::~basic_string()", referenced from:
-[NSString(Demangle) demangledAsSwift] in libZIKRouter.a(NSString+Demangle.o)
-[NSString(Demangle) demangledAsSimplifiedSwift] in libZIKRouter.a(NSString+Demangle.o)
"___gxx_personality_v0", referenced from:
+[ZIKImageSymbol enumerateImages:] in libZIKRouter.a(ZIKImageSymbol.o)
+[ZIKImageSymbol findSymbolInImage:name:] in libZIKRouter.a(ZIKImageSymbol.o)
+[ZIKImageSymbol findSymbolInImage:matching:] in libZIKRouter.a(ZIKImageSymbol.o)
-[NSString(Demangle) demangledAsSwift] in libZIKRouter.a(NSString+Demangle.o)
_demangleSymbolAsString(char const*, unsigned long, DemangleOptions const&) in libZIKRouter.a(NSString+Demangle.o)
-[NSString(Demangle) demangledAsSimplifiedSwift] in libZIKRouter.a(NSString+Demangle.o)
-[NSString(Demangle) demangledAsCPP] in libZIKRouter.a(NSString+Demangle.o)
...
ld: symbol(s) not found for architecture arm64

Can not get userinfo from url.

if use performURL it work well. but if use perform method it does not work.

let url =  "abc://bvc/a?title=1"
//        ZIKAnyViewRouter.performURL(url, path: ZIKViewRoutePath.push(from: self))
        let b = ZIKAnyViewRouter.router(forURL: url)
                b?.perform(ZIKViewRoutePath.push(from: self), configuring: { (config) in
            print("config:\(config.userInfo)")
//            config.addUserInfo(<#T##userInfo: [String : Any]##[String : Any]#>)
            config.prepareDestination = { destination in
                if let destination = destination as? UIViewController{
                    destination.modalPresentationStyle = .overFullScreen
                }
            }

        })

有几点疑问,问问作者

业务模块之间的通讯无法无法独立,按照你方式,因为他必须得需要知道协议,要不然编译都无法通过,那么协议又该放到哪呢?如果放到本库中,那么其他库用到就得依赖本库,除非协议单独提出来,如果协议单独提出来,按照你的设计思路,协议会很多?

获取模块makeDestination 当destination是view而不是controller时崩溃

你好 我用makeDestination 获取子模块view时崩溃 检查源码是- (void)_performGetDestination:(id)destination fromSource:(nullable id)source函数中self.stateBeforeRoute = [destination zix_presentationState];造成的,因为zix_presentationState成controller分类中的扩展方法。然而我们在获取模块的时候这个模块可能是controller 也可能是view 不应该只是controller,希望您能给出解决方案,最后我想说的是 我爱死你这套路由方案了!!!

How to get url from a router?

I'd like to create a global injection method in + (void)AOP_notifyAll_router:(nullable ZIKViewRouter *)router willPerformRouteOnDestination:(id)destination fromSource:(nullable id)source.But there is no URL information in params.

这个方案如何做代码隔离?

比如有两个模块,PostModule和PersonModule,两个模块间无耦合,业务交集通过Provider接口层提供。主APP通过pod引入两个模块,但这样的话主app是可以引用到模块下的所有类的,在APP中就有可能引入模块中的某个类导致与APP耦合。

关于混编

请问混编的话是否需要 ZIKRouter 和 ZRouter 都要导入?

ZIKViewRouter Error

router's action (ZIKRouteActionPerformRoute) catch error: (Error Domain=kZIKViewRouteErrorDomain Code=4 "Unbalanced calls to begin/end appearance transitions for destination. This error occurs when you try and display a view controller before the current view controller is finished displaying. This may cause the UIViewController skips or messes up the order calling -viewWillAppear:, -viewDidAppear:, -viewWillDisAppear: and -viewDidDisappear:, and messes up the route state. Current error reason is already removed destination but destination appears again before -viewDidDisappear: 请问这个是什么原因?

求助大神 如果我有一个路由像下面的那样 我如何得到destination呢 id<LivePlayerPublicInterface> destination = [_livePlayerViewRouter destination];会报错

  • (ZIKDestinationViewRouter(id) )livePlayerViewRouter {
    if (!_livePlayerViewRouter) {
    _livePlayerViewRouter = [ZIKRouterToView(LivePlayerPublicInterface) performFromSource:self.routeSource configuring:^(ZIKViewRouteConfiguration * _Nonnull config) {
    config.routeType = ZIKViewRouteTypeAddAsSubview;
    config.prepareDestination = ^(id _Nonnull destination) {
    [destination setFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenWidth
    3.0/4.0)];
    };
    }];
    }
    return _livePlayerViewRouter;
    }

怎么运行demo

作者您好,能ReadMe写一下,下载demo怎么运行吗?我打开文件夹有点懵。

遇到内存泄漏问题 麻烦大神

当router支持的路由类型是ZIKViewRouteTypeMaskViewDefault时Presenter如果强持有router会造成view的内存泄漏,这种情况下我觉得是router强制持有了绑定的view。我查看了一下源码,仍然没有找到问题的原因,希望大神指点,另外当router绑定的是controller类型时是正常的,view presenter Interactor 等的持有关系我反复核查过,问题并不出现在这个地方。谢谢

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

+ (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

这个怎么回事

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.