Skip to content

Commit

Permalink
Document default initializers themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jan 15, 2020
1 parent af92e71 commit 5f03010
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 78 deletions.
65 changes: 49 additions & 16 deletions MapboxCoreNavigation/NavigationServiceDelegate.swift

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions MapboxCoreNavigation/UnimplementedLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import Dispatch
The default method implementations should be provided as part of the protocol or an extension thereof. If the default implementations reside in an extension, the extension should have the same visibility level as the protocol itself.
*/
public protocol UnimplementedLogging {
/**
Prints a warning to standard output.
*/
func logUnimplemented(protocolType: Any, level: OSLogType, function: String)
}

public extension UnimplementedLogging {

func logUnimplemented(protocolType: Any, level: OSLogType, function: String = #function) {

let protocolDescription = String(describing: protocolType)
Expand All @@ -31,7 +33,7 @@ public extension UnimplementedLogging {
}

let log = OSLog(subsystem: "com.mapbox.navigation", category: "delegation.\(selfDescription)")
let formatted: StaticString = "Unimplemented Delegate Method in %@: %@.%@. This message will only be logged once."
let formatted: StaticString = "Unimplemented delegate method in %@: %@.%@. This message will only be logged once."
os_log(formatted, log: log, type: level, selfDescription, protocolDescription, function)
unimplementedTestLogs?.append((selfDescription, function))
warned.append(description)
Expand Down
48 changes: 36 additions & 12 deletions MapboxNavigation/CarPlayManagerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter carPlayTemplate: The template into which the returned bar buttons will be inserted.
- parameter activity: What the user is currently doing on the CarPlay screen. Use this parameter to distinguish between multiple templates of the same kind, such as multiple `CPMapTemplate`s.
- returns: An array of bar buttons to display on the trailing side of the navigation bar while `template` is visible.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, trailingNavigationBarButtonsCompatibleWith traitCollection: UITraitCollection, in carPlayTemplate: CPTemplate, for activity: CarPlayActivity) -> [CPBarButton]?

Expand All @@ -51,7 +50,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter carPlayTemplate: The template into which the returned map buttons will be inserted.
- parameter activity: What the user is currently doing on the CarPlay screen. Use this parameter to distinguish between multiple templates of the same kind, such as multiple `CPMapTemplate`s.
- returns: An array of map buttons to display on the map while `template` is visible.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, mapButtonsCompatibleWith traitCollection: UITraitCollection, in carPlayTemplate: CPTemplate, for activity: CarPlayActivity) -> [CPMapButton]?

Expand All @@ -62,7 +60,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter route: The route for which the returned route controller will manage location updates.
- parameter desiredSimulationMode: The desired simulation mode to use.
- returns: A navigation service that manages location updates along `route`.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route, desiredSimulationMode: SimulationMode) -> NavigationService

Expand All @@ -73,7 +70,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter searchTemplate: The search template currently accepting user input.
- parameter searchText: The updated search text in `searchTemplate`.
- parameter completionHandler: Called when the search is complete. Accepts a list of search results.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.

- postcondition: You must call `completionHandler` within this method.
*/
Expand All @@ -86,7 +82,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter searchTemplate: The search template currently accepting user input.
- parameter item: The search result the user has selected.
- parameter completionHandler: Called when the delegate is done responding to the selection.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.

- postcondition: You must call `completionHandler` within this method.
*/
Expand All @@ -99,7 +94,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter options: The route options that were attached to the route request.
- parameter error: The error returned from the directions API.
- returns: Optionally, a `CPNavigationAlert` to present to the user. If this method returns an alert, the CarPlay manager will transition back to the map template and display the alert. If it returns `nil`, the CarPlay manager will do nothing.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, didFailToFetchRouteBetween waypoints: [Waypoint]?, options: RouteOptions, error: DirectionsError) -> CPNavigationAlert?

Expand All @@ -111,7 +105,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter carPlayManager: The CarPlay manager instance.
- parameter trip: The trip that will be previewed.
- returns: The actual trip to be previewed. This can be the same trip or a new/alternate trip if desired.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> (CPTrip)

Expand All @@ -122,7 +115,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter trip: The trip that will be previewed.
- parameter previewTextConfiguration: The trip preview text configuration that will be presented alongside the trip.
- returns: The actual preview text configuration to be presented alongside the trip.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> (CPTripPreviewTextConfiguration)

Expand All @@ -132,7 +124,6 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {
- parameter carPlayManager: The CarPlay manager instance.
- parameter trip: The trip to begin navigating along.
- parameter routeChoice: The possible route for the chosen trip.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, selectedPreviewFor trip: CPTrip, using routeChoice: CPRouteChoice) -> ()

Expand All @@ -141,15 +132,13 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {

- parameter carPlayManager: The CarPlay manager instance.
- parameter service: The navigation service that has begun managing location updates for a navigation session.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, didBeginNavigationWith service: NavigationService) -> ()

/**
Called when navigation ends so that the containing app can update accordingly.

- parameter carPlayManager: The CarPlay manager instance.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayManagerDidEndNavigation(_ carPlayManager: CarPlayManager) -> ()

Expand All @@ -160,63 +149,98 @@ public protocol CarPlayManagerDelegate: class, UnimplementedLogging {

- parameter carPlayManager: The CarPlay manager instance.
- returns: A Boolean value indicating whether to disable idle timer when carplay is connected and enable when disconnected.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carplayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool
}

@available(iOS 12.0, *)
public extension CarPlayManagerDelegate {
/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, leadingNavigationBarButtonsCompatibleWith traitCollection: UITraitCollection, in carPlayTemplate: CPTemplate, for activity: CarPlayActivity) -> [CPBarButton]? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, trailingNavigationBarButtonsCompatibleWith traitCollection: UITraitCollection, in carPlayTemplate: CPTemplate, for activity: CarPlayActivity) -> [CPBarButton]? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, mapButtonsCompatibleWith traitCollection: UITraitCollection, in carPlayTemplate: CPTemplate, for activity: CarPlayActivity) -> [CPMapButton]? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, searchTemplate: CPSearchTemplate, updatedSearchText searchText: String, completionHandler: @escaping ([CPListItem]) -> Void) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, searchTemplate: CPSearchTemplate, selectedResult item: CPListItem, completionHandler: @escaping () -> Void) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, didFailToFetchRouteBetween waypoints: [Waypoint]?, options: RouteOptions, error: DirectionsError) -> CPNavigationAlert? {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> (CPTrip) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return trip
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> (CPTripPreviewTextConfiguration) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return previewTextConfiguration
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, selectedPreviewFor trip: CPTrip, using routeChoice: CPRouteChoice) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManager(_ carPlayManager: CarPlayManager, didBeginNavigationWith service: NavigationService) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayManagerDidEndNavigation(_ carPlayManager: CarPlayManager) {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carplayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool {
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
return false
Expand Down
4 changes: 3 additions & 1 deletion MapboxNavigation/CarPlayNavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ public protocol CarPlayNavigationDelegate: class, UnimplementedLogging {

- parameter carPlayNavigationViewController: The CarPlay navigation view controller that was dismissed.
- parameter canceled: True if the user dismissed the CarPlay navigation view controller by tapping the Cancel button; false if the navigation view controller dismissed by some other means.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func carPlayNavigationViewControllerDidDismiss(_ carPlayNavigationViewController: CarPlayNavigationViewController, byCanceling canceled: Bool)

Expand All @@ -554,6 +553,9 @@ public protocol CarPlayNavigationDelegate: class, UnimplementedLogging {

@available(iOS 12.0, *)
public extension CarPlayNavigationDelegate {
/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func carPlayNavigationViewControllerDidDismiss(_ carPlayNavigationViewController: CarPlayNavigationViewController, byCanceling canceled: Bool) {
logUnimplemented(protocolType: CarPlayNavigationDelegate.self, level: .debug)
}
Expand Down
12 changes: 9 additions & 3 deletions MapboxNavigation/FeedbackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,38 @@ extension FeedbackViewController: UIViewControllerTransitioningDelegate {
public protocol FeedbackViewControllerDelegate: class, UnimplementedLogging {
/**
Called when the user opens the feedback form.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func feedbackViewControllerDidOpen(_ feedbackViewController: FeedbackViewController)

/**
Called when the user submits a feedback event.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSend feedbackItem: FeedbackItem, uuid: UUID)

/**
Called when a `FeedbackViewController` is dismissed for any reason without giving explicit feedback.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func feedbackViewControllerDidCancel(_ feedbackViewController: FeedbackViewController)
}

public extension FeedbackViewControllerDelegate {
/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func feedbackViewControllerDidOpen(_ feedbackViewController: FeedbackViewController) {
logUnimplemented(protocolType: FeedbackViewControllerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSend feedbackItem: FeedbackItem, uuid: UUID) {
logUnimplemented(protocolType: FeedbackViewControllerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func feedbackViewControllerDidCancel(_ feedbackViewController: FeedbackViewController) {
logUnimplemented(protocolType: FeedbackViewControllerDelegate.self, level: .debug)
}
Expand Down
4 changes: 3 additions & 1 deletion MapboxNavigation/InstructionLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public protocol VisualInstructionDelegate: class, UnimplementedLogging {
- parameter instruction: the `VisualInstruction` that will be presented.
- parameter presented: the formatted string that is provided by the instruction presenter
- returns: optionally, a customized NSAttributedString that will be presented instead of the default, or if nil, the default behavior will be used.
- note: This delegate method includes a default implementation that prints a warning to the console when this method is called. See `UnimplementedLogging` for details.
*/
func label(_ label: InstructionLabel, willPresent instruction: VisualInstruction, as presented: NSAttributedString) -> NSAttributedString?
}

public extension VisualInstructionDelegate {
/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func label(_ label: InstructionLabel, willPresent instruction: VisualInstruction, as presented: NSAttributedString) -> NSAttributedString? {
logUnimplemented(protocolType: InstructionLabel.self, level: .debug)
return nil
Expand Down
Loading

0 comments on commit 5f03010

Please sign in to comment.