Introduction
Welcome to the documentation for ljURLRouter – a powerful URL routing library for iOS. This documentation will guide you through the usage, features, and integration of ljURLRouter in your iOS applications.
Installation
To install ljURLRouter in your iOS project, you have two options:
- Using CocoaPods:
Add the following line to your Podfile:
pod 'ljURLRouter', '~> 5.0'
Then run the command:
pod install
- Manually:
Download and unzip the source code from the GitHub repository. Drag and drop the
ljURLRouter
folder into your Xcode project.
Usage
Routing Configuration
Before you can start using ljURLRouter, you need to configure the routing paths and their associated handlers. Here’s how:
- Import the
ljURLRouter
module in your Swift file:
import ljURLRouter
- Create a global instance of
ljURLRouter
:
let router = ljURLRouter.shared
- Define the routing paths and their handlers by calling the
register(_:handler:)
method:
router.register("path/to/route") { (parameters) in // Handle the route here }
Routing
To navigate to a specific route in your application, use the route(_:parameters:)
method:
router.route("path/to/route") // or router.route("path/to/route", parameters: ["key": value])
Parameter Extraction
If your route contains parameters, you can extract them using the parameter(forName:)
method:
let value = router.parameter(forName: "key")
Navigation Controller Integration
ljURLRouter provides seamless integration with UINavigationController
. Here are the steps to follow:
- Import the
ljURLRouter
module in your Swift file:
import ljURLRouter
- Create a subclass of
ljURLRouterNavigationController
for your navigation controller:
class CustomNavigationController: ljURLRouterNavigationController { // Customize your navigation controller here }
- Instantiate your navigation controller subclass:
let navigationController = CustomNavigationController(rootViewController: yourRootViewController)
- Set the navigation controller as the window’s root view controller:
window?.rootViewController = navigationController
Conclusion
Congratulations! You have successfully integrated ljURLRouter into your iOS application. Enjoy its powerful URL routing capabilities for easy navigation and parameter extraction.