Skip to content

Commit

Permalink
Rename delegate method to conform to Swift API design guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni committed Sep 18, 2018
1 parent 1cc945b commit 0fb1920
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to the Mapbox Navigation SDK for iOS

## master

`StyleManagerDelegate.locationFor(styleManager:)` has been renamed to `StyleManagerDelegate.location(for:)` ([#1724](https://github.com/mapbox/mapbox-navigation-ios/pull/1724))

## v0.21.0 (September 17, 2018)

### User interface
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/CarPlayMapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CarPlayMapViewController: UIViewController, MGLMapViewDelegate {

@available(iOS 12.0, *)
extension CarPlayMapViewController: StyleManagerDelegate {
func locationFor(styleManager: StyleManager) -> CLLocation? {
func location(for styleManager: StyleManager) -> CLLocation? {
return mapView.userLocationForCourseTracking ?? mapView.userLocation?.location ?? coarseLocationManager.location
}

Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/CarPlayNavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public class CarPlayNavigationViewController: UIViewController, MGLMapViewDelega

@available(iOS 12.0, *)
extension CarPlayNavigationViewController: StyleManagerDelegate {
public func locationFor(styleManager: StyleManager) -> CLLocation? {
public func location(for styleManager: StyleManager) -> CLLocation? {
return routeController.locationManager.location
}

Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ extension NavigationViewController: TunnelIntersectionManagerDelegate {

extension NavigationViewController: StyleManagerDelegate {

public func locationFor(styleManager: StyleManager) -> CLLocation? {
public func location(for styleManager: StyleManager) -> CLLocation? {
if let location = routeController.location {
return location
} else if let firstCoord = routeController.routeProgress.route.coordinates?.first {
Expand Down
9 changes: 5 additions & 4 deletions MapboxNavigation/StyleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public protocol StyleManagerDelegate: NSObjectProtocol {
/**
Asks the delegate for a location to use when calculating sunset and sunrise.
*/
@objc func locationFor(styleManager: StyleManager) -> CLLocation?
@objc(locationForStyleManager:)
func location(for styleManager: StyleManager) -> CLLocation?

/**
Informs the delegate that a style was applied.
Expand Down Expand Up @@ -95,7 +96,7 @@ open class StyleManager: NSObject {
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(timeOfDayChanged), object: nil)

guard automaticallyAdjustsStyleForTimeOfDay && styles.count > 1 else { return }
guard let location = delegate?.locationFor(styleManager: self) else { return }
guard let location = delegate?.location(for:self) else { return }

guard let solar = Solar(date: date, coordinate: location.coordinate),
let sunrise = solar.sunrise,
Expand Down Expand Up @@ -137,7 +138,7 @@ open class StyleManager: NSObject {
}

func applyStyle() {
guard let location = delegate?.locationFor(styleManager: self) else {
guard let location = delegate?.location(for: self) else {
// We can't calculate sunset or sunrise w/o a location so just apply the first style
if let style = styles.first, currentStyleType != style.styleType {
currentStyleType = style.styleType
Expand Down Expand Up @@ -172,7 +173,7 @@ open class StyleManager: NSObject {
}

func forceRefreshAppearanceIfNeeded() {
guard let location = delegate?.locationFor(styleManager: self) else { return }
guard let location = delegate?.location(for: self) else { return }

let styleTypeForLocation = styleType(for: location)

Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigationTests/NavigationViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class NavigationViewControllerTests: XCTestCase {
}

extension NavigationViewControllerTests: NavigationViewControllerDelegate, StyleManagerDelegate {
func locationFor(styleManager: StyleManager) -> CLLocation? {
func location(for styleManager: StyleManager) -> CLLocation? {
return dependencies.poi.first!
}

Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigationTests/StyleManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extension StyleManagerTests: StyleManagerDelegate {
func styleManagerDidRefreshAppearance(_ styleManager: StyleManager) { }
func styleManager(_ styleManager: StyleManager, didApply style: Style) { }

func locationFor(styleManager: StyleManager) -> CLLocation? {
func location(for styleManager: StyleManager) -> CLLocation? {
return location
}
}

0 comments on commit 0fb1920

Please sign in to comment.