AftermathCompass is a message-driven routing system built on top of Aftermath and Compass.
Create your first route and error handler.
import Compass
structUserRoute:Routable{func navigate(to location:Location, from currentController:Controller)throws{guardlet id = location.arguments["id"]else{throwRouteError.InvalidArguments(location)}letcontroller=UserController(id: id)
currentController.navigationController?.pushViewController(controller, animated:true)}}structErrorRoute:ErrorRoutable{func handle(routeError:ErrorType, from currentController:Controller){letcontroller=ErrorController(error: routeError)
currentController.navigationController?.pushViewController(controller, animated:true)}}Optionally, you can create a command route to build new commands based on
Location:
classUpdateUserRoute:CommandRoute{func buildCommand(from location:Location)throws->AnyCommand{
guard let params = location.payload as?User{throw UserError
}
return UpdateUserCommand(parameters: params)}}Configure Compass scheme, router and Aftermath in your AppDelegate:
@UIApplicationMainclassAppDelegate:UIResponder,UIApplicationDelegate{letrouter=Router()letcommandRouter=CommandRouter()varcompassManager:CompassManager!
lazy varnavigationController=UINavigationController(rootViewController:ViewController())
lazy varwindow:UIWindow?={letwindow=UIWindow(frame:UIScreen.mainScreen().bounds)return window
}()func currentController()->UIViewController{return navigationController.topViewController!
}
// ...
func application(application:UIApplication,
didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?)->Bool{
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
// ...
configureCompass()returntrue}func configureCompass(){
router.errorRoute =ErrorRoute()
router.routes =["users:{id}":UserRoute()]
commandRouter.routes =["users:update:{id}":UpdateUserRoute()]Compass.scheme ="aftermath"Compass.routes =Array(router.routes.keys)+ Array(commandRouter.routes.keys)
compassManager =CompassManager(
router:{self.router },
commandRouter:{self.commandRouter },
currentController: currentController
)}
// ...
}Start your journey:
import Aftermath
import AftermathCompass
classViewController:UIViewController,CommandProducer{
// ...
// Navigate to URN
func openUser(id:Int){execute(CompassCommand(URN:"users:\(id)"))}
// Execute command from URN
func updateUser(user:User){execute(CompassCommand(URN:"users:\(user.id)", payload: user))}
// ...
}AftermathCompass is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod'AftermathCompass'AftermathCompass is also available through Carthage. To install just write into your Cartfile:
github"hyperoslo/AftermathCompass"AftermathCompass can also be installed manually. Just download and drop Sources folders in your project.
Hyper Interaktiv AS, ios@hyper.no
We would love you to contribute to AftermathCompass, check the CONTRIBUTING file for more info.
AftermathCompass is available under the MIT license. See the LICENSE file for more info.