RMRoute 0.9.2

RMRoute 0.9.2

TestsTested
LangLanguage SwiftSwift
License Apache-2.0
ReleasedLast Release Sep 2019
SPMSupports SPM

Maintained by Niels Koole, Paul van Roosendaal, Roadmap.



RMRoute 0.9.2

  • By
  • Roadmap

RMRoute

CocoaPods Compatible Twitter

RMRoute is a lightweight implementation to use routes in your iOS application.

Summary

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.

Features

  • Registering & calling routes
  • Pass parameters in route
  • Routes case insensitive
  • Swift 3 compatible
  • Named parameters

Requirements

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0

Installation

CocoaPods

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

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Alamofire into your project manually.

Usage

Registering a route

Simple registration

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;
}];

More advanced registration

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;
}];

Calling a route

Simple call

Example without parameters

import RMRoute

RMRoute.navigate("about", delegate: self, animation: .push)
[RMRoute navigate:@"about" delegate:self animation:RMRouteAnimationPush];

More advanced call

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

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!

License

RMRoute is released under the Apache license. See LICENSE for details.