RMRoute is a lightweight implementation to use routes in your iOS application.
- Summary
- Features
- Requirements
- Installation
- Usage
- Registering routes - Simple registration (without parameters), More advanced registration (with parameters)
- Calling routes - Simple call, More advanced call
- Credits
- License
RMRoute makes it easy to provide access to all your features from anywhere in your app. With bigger applications it's sometimes handy to have entry points to your features, without referencing to them by class.
- Registering & calling routes
- Pass parameters in route
- Routes case insensitive
- Swift 3 compatible
- Named parameters
- iOS 8.0+
- Xcode 8.0+
- Swift 3.0
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.0.0+ is required to build RMRoute.
To integrate RMRoute into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'RMRoute'
end
Then, run the following command:
$ pod install
If you prefer not to use either of the aforementioned dependency managers, you can integrate Alamofire into your project manually.
Example without parameters
import RMRoute
RMRoute.register("about") { (delegate, animation, params) in
// Just show the vc
let vc = AboutViewController()
delegate.animate(vc, animation: animation) // This is an UIViewController extension which handles the animation type
return true
}
[RMRoute registerWithPath:@"about" action:^BOOL (UIViewController *delegate, RMRouteAnimation animation, NSArray *params) {
// Just show the vc
AboutViewController *vc = [[AboutViewController alloc] init];
[delegate animate:vc animation:animation]; // This is an UIViewController extension which handles the animation type
return YES;
}];
Example with parameters. You can also use query string parameters: "faq/?itemId={itemId}".
import RMRoute
RMRoute.register("faq/{itemId}") { (delegate, animation, params) in
let itemId = params[0]
guard itemId.isEmpty == false else {
return false
}
// Just show the vc
let vc = FAQViewController(itemId)
delegate.animate(vc, animation: animation)
return true
}
[RMRoute registerWithPath:@"faq/{itemId}" action:^BOOL (UIViewController *delegate, RMRouteAnimation animation, NSArray *params) {
NSString *itemId = params[0];
if (itemId.length == 0) return NO;
// Just show the vc
FAQViewController *vc = [[FAQViewController alloc] initWithItemId:itemId];
[delegate animate:vc animation:animation];
return YES;
}];
Example without parameters
import RMRoute
RMRoute.navigate("about", delegate: self, animation: .push)
[RMRoute navigate:@"about" delegate:self animation:RMRouteAnimationPush];
Example with parameters
import RMRoute
RMRoute.navigate("faq/12", delegate: self, animation: .present)
RMRoute.navigate("faq/?itemId=12", delegate: self, animation: .present)
[RMRoute navigate:@"faq/12" delegate:self animation:RMRouteAnimationPresent];
[RMRoute navigate:@"faq/?itemId=12" delegate:self animation:RMRouteAnimationPresent];
Credits to the Roadmap team to make this all possible! Really a great team, if you're looking for a new challenge please get in contact with us! We're always open to discuss the future with a good cup of coffee!
RMRoute is released under the Apache license. See LICENSE for details.