Coder Social home page Coder Social logo

rmroute's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.