How huolalatech/hll-wp-therouter-ios works
Project Type and Purpose
• This repository is an iOS routing library (“TheRouter”) with accompanying demo applications (Swift Example and Objective-C Example).
• It provides a modular, protocol-oriented URL‐based navigation and service invocation framework for decoupling iOS app components, supporting both Swift and Objective-C.
File-Structure Analysis
Top-level:
• .gitignore, .travis.yml, LICENSE, README.md – CI/configuration and documentation.
• Example/… – Swift demo app showing how an end consumer integrates and exercises TheRouter.
• TheRouter-ObjectiveCDemo/… – Objective-C demo app with CocoaPods setup and Bridging Headers.
• TheRouter/… – Core framework sources:
– Classes/ – Swift + Obj-C source files for TheRouter runtime (Manager, Parser, ServiceManager, Builder, Interceptor, DebugTool, etc.).
– Assets/ – placeholder for resource assets in the pod.
– TheRouterable/ – SPM package for the TheRouterable protocol.
– TheRouterMacro/ – Swift Package manifest and code for a CLI/macro that can generate boilerplate or assist routing registration.
• TheRouter.podspec – Podspec for CocoaPods distribution.
• _Pods.xcodeproj – aggregated workspace for local development/testing of the pod.
Architectural Insights from README
• Core responsibilities:
1. Lazy route registration via runtime class scanning (objc_copyClassNames…) and filtering by prefix.
2. Pattern→ViewController mapping driven by TheRouterable or CustomRouterInfo protocols.
3. URL parsing and builder (TheRouterParser, TheRouterBuilder) for chainable parameter setting.
4. Navigation dispatch (push/present/tabBar/modal) handled by LARouterPresentController extension points.
5. Service discovery/injection via TheRouterServiceProtocol and TheRouterServiceManager.
6. Dynamic features: interceptors, redirections, hot path repair, runtime add/remove routes, caching, global failure handling, compatibility with OC classes (TheRouterableProxy).
Main Components and Their Relationships
A. Host App (Example or Objective-C Demo)
– Calls TheRouter.lazyRegisterRouterHandle on launch.
– Invokes navigation: TheRouter.openURL(), TheRouterBuilder.build().navigation().
– Fetches services: TheRouter.fetchService(...).
B. Router Core (TheRouter Pod)
1. RouterManager
• Manages registration lifecycle (lazy vs. cache).
• Coordinates scanning and adding routes/services.
2. PatternRegistry
• Stores mapping of URL patterns ↔ class names.
3. Parser & Builder
• Parses incoming URL strings.
• Provides chainable parameter APIs.
4. Navigation Controller Extensions
• LARouterPresentController chooses push/present logic.
5. ServiceManager
• Registers and retrieves service implementations by protocol name.
6. Interceptor & Redirection Handlers
• Allow pre-navigation logic and dynamic path remapping.
7. Debug & Logging
• TheRouterDebugTool and log callback entry point.
C. Macro/Codegen (TheRouterMacro)
– SPM target that can generate routing boilerplate or assist in code instrumentation.
– Invoked at build time to emit static constants or convenience APIs.
D. External Dependencies
– CocoaPods / SPM distribution mechanism.
– iOS SDK (UIKit navigation stacks).
– Objective-C runtime APIs (objc_copyClassNamesForImage, NSClassFromString).