Created
March 31, 2021 18:31
-
-
Save Rashidium/b665238412e2e599db2491729b41598c to your computer and use it in GitHub Desktop.
CustomerLink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct CustomerLink: AppLinkable { | |
public var customerNo: Int64! | |
init() { | |
} | |
init(customerNo: Int64) { | |
self.customerNo = customerNo | |
} | |
public func getLinkable(_ url: URL) -> Self? { | |
let string = url.path | |
guard string.hasPrefix("/customer") else { return nil } | |
let customerNoString = string | |
.replacingOccurrences(of: "/customer", with: "") | |
.replacingOccurrences(of: "/", with: "") | |
guard let customerNo = Int64(customerNoString) else { return nil } | |
return Self.init(customerNo: customerNo) | |
} | |
public func link(from router: AppLinkRoutable) { | |
(router as? CustomerLinkRoutable)?.customerDetailLinkRoute(self) | |
} | |
} | |
public protocol CustomerLinkRoutable: AppLinkRoutable { | |
func customerLinkRoute(_ link: CustomerLink) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment