Skip to content

Commit

Permalink
Log coordinator actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdrobne committed Mar 18, 2024
1 parent 920303c commit dcb5a98
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
13 changes: 12 additions & 1 deletion Sources/SwiftUICoordinator/Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public protocol Coordinator: AnyObject {
var parent: Coordinator? { get }
/// An array that stores references to any child coordinators.
var childCoordinators: [WeakCoordinator] { get set }
/// Coordinator type name
var name: String { get }
/// Takes action parameter and handles the `CoordinatorAction`.
func handle(_ action: CoordinatorAction)
/// Adds child coordinator to the list.
Expand All @@ -27,11 +29,19 @@ public protocol Coordinator: AnyObject {

public extension Coordinator {

// MARK: - Public properties

var name: String {
return String(describing: type(of: self))
}

// MARK: - Public methods

func add(child: Coordinator) {
guard !childCoordinators.contains(where: { $0 === child }) else {
Logger.coordinator.warning("Attempted to add a coordinator that is already a child.")
Logger.coordinator.warning(
"Attempted to add a coordinator that is already a child: \(self.name)"
)
return
}

Expand All @@ -40,5 +50,6 @@ public extension Coordinator {

func remove(coordinator: Coordinator) {
childCoordinators.removeAll(where: { $0.coordinator === coordinator })
Logger.coordinator.notice("Removed coordinator: \(self.name)")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// CoordinatorDeepLinkHandling.swift
//
//
// Created by Erik Drobne on 12. 10. 23.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// WeakCoordinator.swift
//
//
// Created by Erik Drobne on 9. 10. 23.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftUICoordinator/DeepLink/DeepLinkError.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// DeepLinkError.swift
//
//
// Created by Erik Drobne on 13/09/2023.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftUICoordinator/DeepLink/DeepLinkHandling.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// DeepLinkHandling.swift
//
//
// Created by Erik Drobne on 13/09/2023.
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftUICoordinator/Navigator/Navigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import OSLog

public typealias Routing = Coordinator & Navigator

Expand Down

0 comments on commit dcb5a98

Please sign in to comment.