Description
CocoaDocs is a platform for documentation of Cocoa libraries. One of the libraries available on CocoaDocs is HzUrlManager, which is a powerful URL routing library for iOS.
Features
- URL routing and navigation
- Easy setup and integration
- Flexible and customizable routing patterns
- Supports both push and present navigation
- Route parameters and query string handling
- Deep linking support
- Object passing between view controllers
- Route filtering and validation
Installation
HzUrlManager is available through CocoaPods, which is a dependency manager for Cocoa projects. To install it, simply add the following line to your Podfile:
pod 'HzUrlManager'
Then, run the following command:
pod install
Usage
Using HzUrlManager is straightforward. Simply follow the steps below:
1. Import HzUrlManager
import HzUrlManager
2. Setup URL mappings
In your AppDelegate, add the necessary URL mappings for your app. HzUrlManager provides a simple interface for setting up your URL mappings.
HzUrlManager.shared.addURLPattern("/home", handler: HomeHandler())
HzUrlManager.shared.addURLPattern("/profile/:id", handler: ProfileHandler())
HzUrlManager.shared.addURLPattern("/settings")
// Add more URL mappings as needed
In the example above, the first URL mapping will be handled by the HomeHandler, the second URL mapping will be handled by the ProfileHandler (passing the value of “id” as a parameter), and the third URL mapping will be handled by a default handler for the “/settings” URL.
3. Handle the URL in a ViewController
In the View Controller, conform to the `HzUrlHandler` protocol and implement the `handleUrl` method to handle the corresponding URL.
class HomeHandler: HzUrlHandler {
func handleUrl(_ url: URL, parameters: [String : String]) {
// Handle the "/home" URL
}
}
class ProfileHandler: HzUrlHandler {
func handleUrl(_ url: URL, parameters: [String : String]) {
// Handle the "/profile/:id" URL
if let id = parameters["id"] {
// Use the id to show corresponding profile
}
}
}
The `handleUrl` method allows you to perform actions or navigate to different view controllers based on the URL.
Example
Here’s an example of how to use HzUrlManager:
// Open the "/home" URL
HzUrlManager.shared.open("http://example.com/home")
// Open the "/profile" URL with a parameter
HzUrlManager.shared.open("http://example.com/profile/123")
// Open the "/settings" URL
HzUrlManager.shared.open("http://example.com/settings")
These calls will trigger the corresponding handlers and perform the necessary actions based on the provided URLs.
Documentation
For a more detailed documentation and reference, please visit the CocoaDocs page for HzUrlManager.