RMRoute 0.9.2

RMRoute 0.9.2

测试已测试
语言语言 SwiftSwift
许可证 Apache-2.0
版本最后发布2019年9月
SPM支持 SPM

RoadmapNiels KoolePaul van Roosendaal 维护。



RMRoute 0.9.2

  • Roadmap

RMRoute

CocoaPods Compatible Twitter

RMRoute 是一个轻量级的实现,用于在 iOS 应用程序中使用路由。

总结

RMRoute 使得从应用程序的任何地方都可以轻松地提供对所有功能的访问。对于更大的应用程序,有时候方便有为您的功能提供入口点,而不是通过类来引用它们。

特性

  • 注册和调用路由
  • 在路由中传递参数
  • 路由不区分大小写
  • 兼容 Swift 3
  • 命名参数

要求

  • 支持iOS 8.0+
  • 支持Xcode 8.0+
  • Swift 3.0

安装

CocoaPods

CocoaPods 是用于 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:

$ gem install cocoapods

构建 RMRoute 需要使用 CocoaPods 1.0.0+。

要使用 CocoaPods 将 RMRoute 集成到您的 Xcode 项目中,请在其 Podfile 中指定它。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'RMRoute'
end

然后,运行以下命令:

$ pod install

手动集成

如果您不想使用上述任何一个依赖管理器,您可以将 Alamofire 手动集成到您的项目中。

使用方法

注册路由

简单注册

无参数示例

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

更高级的注册

带参数的示例。您也可以使用查询字符串参数:"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;
}];

调用一个路由

简单调用

无参数示例

import RMRoute

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

更高级调用

带参数的示例

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

积分

感谢路线图团队使这一切成为可能!真是一个伟大的团队,如果您正在寻找新的挑战,请与我们联系!我们随时敞开大门,用一杯咖啡讨论未来!

许可协议

RMRoute在Apache许可下发布。有关详细信息,请参阅LICENSE。