Skip to content

Instantly share code, notes, and snippets.

View Rashidium's full-sized avatar

Rashid Ramazanov Rashidium

View GitHub Profile
@Rashidium
Rashidium / DeepLinkManager.swift
Last active July 22, 2021 21:04
DeepLinkManager payload presentation
extension DeeplinkManager {
/// Returns linkable satisfied with the payload.
/// - Parameter payload: Push notification payload of the deeplink.
/// - Returns: Linkable satisfied with the payload.
public func getLinkable(payload: [AnyHashable: Any]) -> AppLinkable? {
for (index, link) in links.enumerated() {
guard let activeLink = link.getLinkable(payload: payload) else { continue }
links[index] = activeLink
return activeLink
}
@Rashidium
Rashidium / AppDelegate.swift
Last active July 23, 2021 22:16
AppDelegate with CustomerLinkRoutable conformance
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var deeplinkManager: DeeplinkManager!
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
deeplinkManager = DeeplinkManager(supportedLinks: [CustomerLink()])
}
@discardableResult func application(
/// AppLinkable's for deeplink navigation.
public protocol AppLinkable {
/// Returns AppLinkable if url is satisfied
/// - Parameter url: URL of deeplink
func getLinkable(_ url: URL) -> Self?
/// Returns OneLinkable if url is satisfied.
/// - Parameter payload: Push notification payload of the deeplink.
func getLinkable(payload: [AnyHashable: Any]) -> Self?
@Rashidium
Rashidium / CustomerLinkRoutable.swift
Created March 31, 2021 18:25
CustomerLinkRoutable
public protocol CustomerLinkRoutable: AppLinkRoutable {
func customerLinkRoute(_ link: CustomerLink)
}
@Rashidium
Rashidium / AppLinkRoutable.swift
Created March 31, 2021 18:23
AppLinkRoutable protocol
/// Routing conformance for the Main scene.
public protocol AppLinkRoutable {
// Should be implemented for each link.
}
@Rashidium
Rashidium / AppLinkable+Extension.swift
Created March 31, 2021 18:10
AppLinkable extension for getLinkable(payload:)
public extension AppLinkable {
func getLinkable(payload: [AnyHashable: Any]) -> Self? {
return nil
}
}
@Rashidium
Rashidium / AppLinkable.swift
Last active March 31, 2021 18:19
AppLinkable with payload
/// AppLinkable's for deeplink navigation.
public protocol AppLinkable {
/// Returns AppLinkable if url is satisfied
/// - Parameter url: URL of deeplink
func getLinkable(_ url: URL) -> Self?
/// Returns AppLinkable if url is satisfied.
/// - Parameter payload: Push notification payload of the deeplink.
func getLinkable(payload: [AnyHashable: Any]) -> Self?
@Rashidium
Rashidium / DeeplinkManager.swift
Last active July 23, 2021 22:16
DeeplinkManager
/// Manager for deeplinks.
public final class DeeplinkManager {
/// Application supported deeplinks.
private var links: [AppLinkable]
/// Initializes manager with supported links.
public init(supportedLinks links: [AppLinkable]) {
self.links = links
}
@Rashidium
Rashidium / AppLinkable.swift
Last active March 31, 2021 18:19
AppLinkable with getLinkable function
/// AppLinkable's for deeplink navigation.
public protocol AppLinkable {
/// Returns AppLinkable if url is satisfied
/// - Parameter url: URL of deeplink
func getLinkable(_ url: URL) -> Self?
}