File tree Expand file tree Collapse file tree 5 files changed +45
-9
lines changed
Expand file tree Collapse file tree 5 files changed +45
-9
lines changed Original file line number Diff line number Diff line change 11import Foundation
22
3+ /// This struct enriches a route with the parameters that came along with the URL,
4+ /// making it possible to perform the route action
5+ ///
36struct MatchedRoute {
47 let route : Route
58 let parameters : [ String : String ]
69
710 func performAction( ) {
8- route. action . perform ( with: parameters)
11+ route. perform ( with: parameters)
912 }
1013}
1114
15+ /// RouterMatcher finds URL routes with paths that match the path of a specified URL,
16+ /// and extracts parameters from the URL.
17+ ///
1218class RouteMatcher {
1319 let routes : [ Route ]
1420
Original file line number Diff line number Diff line change 1+ import Foundation
2+
3+ /// Shows order details from a given universal link that matches the right path
4+ ///
5+ struct OrderDetailsRoute : Route {
6+ let path = " /orders/details "
7+
8+ func perform( with parameters: [ String : String ] ) {
9+ DDLogInfo ( " We received an order details universal link with parameters: \( parameters) " )
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ import UIKit
2+ import Foundation
3+
4+ /// A universal link route, used to encapsulate a URL path and action
5+ ///
6+ protocol Route {
7+ var path : String { get }
8+
9+ func perform( with parameters: [ String : String ] )
10+ }
Original file line number Diff line number Diff line change 11import Foundation
22import UIKit
33
4- protocol LinkRouter {
5- init ( routes: [ Route ] )
6- func handle( url: URL )
7- }
8-
9- struct UniversalLinkRouter : LinkRouter {
4+ /// Keeps a list of possible URL routes that are exposed
5+ /// via universal links, and handles incoming links to trigger the appropriate route.
6+ ///
7+ struct UniversalLinkRouter {
108 private let matcher : RouteMatcher
119
10+ /// The order of the passed Route array matters, as given two routes that handle a path only the first
11+ /// will be called to perform its action
12+ ///
1213 init ( routes: [ Route ] ) {
1314 matcher = RouteMatcher ( routes: routes)
1415 }
Original file line number Diff line number Diff line change 68866886 B958A7C528B3D42000823EEF /* Universal Links */ = {
68876887 isa = PBXGroup;
68886888 children = (
6889+ B958A7CE28B50FAE00823EEF /* Routes */,
68896890 B958A7C628B3D44A00823EEF /* UniversalLinkRouter.swift */,
6890- B958A7C828B3D47B00823EEF /* Route.swift */,
68916891 B958A7CA28B3D4A100823EEF /* RouteMatcher.swift */,
6892- B958A7CC28B3DD9100823EEF /* OrderDetailsRoute.swift */,
68936892 );
68946893 path = "Universal Links";
68956894 sourceTree = "<group>";
68966895 };
6896+ B958A7CE28B50FAE00823EEF /* Routes */ = {
6897+ isa = PBXGroup;
6898+ children = (
6899+ B958A7CC28B3DD9100823EEF /* OrderDetailsRoute.swift */,
6900+ B958A7C828B3D47B00823EEF /* Route.swift */,
6901+ );
6902+ path = Routes;
6903+ sourceTree = "<group>";
6904+ };
68976905 B9B0391B28A690DA00DC1C83 /* PermanentNotice */ = {
68986906 isa = PBXGroup;
68996907 children = (
You can’t perform that action at this time.
0 commit comments