Skip to content

Commit

Permalink
ensure self usage via SwiftFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Kladek committed Apr 15, 2024
1 parent 1f63985 commit ba33a72
Show file tree
Hide file tree
Showing 79 changed files with 1,787 additions and 1,787 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
--patternlet hoist
--ranges spaced
--redundanttype infer-locals-only
--self remove
--self insert
--selfrequired
--semicolons inline
--shortoptionals except-properties
Expand Down
4 changes: 2 additions & 2 deletions MapboxCoreNavigation/CLLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension CLLocation {
// MARK: - Route Snapping

func snapped(to legProgress: RouteLegProgress) -> CLLocation? {
let coords = coordinates(for: legProgress)
let coords = self.coordinates(for: legProgress)

guard let closest = Polyline(coords).closestCoordinate(to: coordinate) else { return nil }
guard let calculatedCourseForLocationOnStep = interpolatedCourse(along: coords) else { return nil }
Expand All @@ -79,7 +79,7 @@ extension CLLocation {
let userCoordinate = closest.coordinate
guard let firstCoordinate = legProgress.leg.steps.first?.coordinates?.first else { return nil }

guard shouldSnapCourse(toRouteWith: calculatedCourseForLocationOnStep, distanceToFirstCoordinateOnLeg: coordinate.distance(to: firstCoordinate)) else { return nil }
guard self.shouldSnapCourse(toRouteWith: calculatedCourseForLocationOnStep, distanceToFirstCoordinateOnLeg: coordinate.distance(to: firstCoordinate)) else { return nil }

guard closest.distance <= (RouteControllerUserLocationSnappingDistance + horizontalAccuracy) else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/CoreFeedbackEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CoreFeedbackEvent: Hashable {
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(self.id)
}

static func == (lhs: CoreFeedbackEvent, rhs: CoreFeedbackEvent) -> Bool {
Expand Down
56 changes: 28 additions & 28 deletions MapboxCoreNavigation/DistanceFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension CLLocationDistance {

// Returns the distance converted to yards
var yards: Double {
feet / 3
self.feet / 3
}

// Returns the distance converted to kilometers
Expand All @@ -43,15 +43,15 @@ extension CLLocationDistance {
case .meter:
return self
case .kilometer:
return kilometers
return self.kilometers
case .inch:
return feet * 12
return self.feet * 12
case .foot:
return feet
return self.feet
case .yard:
return yards
return self.yards
case .mile:
return miles
return self.miles
@unknown default:
fatalError("Unknown unit")
}
Expand All @@ -67,7 +67,7 @@ struct RoundingTable {

@available(iOS 10.0, *)
func measurement(for distance: CLLocationDistance) -> Measurement<UnitLength> {
switch unit {
switch self.unit {
case .millimeter:
return Measurement(value: distance.kilometers / 1e6, unit: .millimeters)
case .centimeter:
Expand All @@ -90,30 +90,30 @@ struct RoundingTable {
}

func localizedDistanceString(for distance: CLLocationDistance, using formatter: DistanceFormatter) -> String {
switch unit {
switch self.unit {
case .mile:
formatter.string(fromValue: distance.miles, unit: unit)
formatter.string(fromValue: distance.miles, unit: self.unit)
case .foot:
formatter.string(fromValue: distance.feet, unit: unit)
formatter.string(fromValue: distance.feet, unit: self.unit)
case .yard:
formatter.string(fromValue: distance.yards, unit: unit)
formatter.string(fromValue: distance.yards, unit: self.unit)
case .kilometer:
formatter.string(fromValue: distance.kilometers, unit: unit)
formatter.string(fromValue: distance.kilometers, unit: self.unit)
default:
formatter.string(fromValue: distance, unit: unit)
formatter.string(fromValue: distance, unit: self.unit)
}
}
}

let thresholds: [Threshold]

func threshold(for distance: CLLocationDistance) -> Threshold {
for threshold in thresholds {
for threshold in self.thresholds {
if distance < threshold.maximumDistance {
return threshold
}
}
return thresholds.last!
return self.thresholds.last!
}
}

Expand Down Expand Up @@ -155,28 +155,28 @@ open class DistanceFormatter: LengthFormatter {
- parameter approximate: approximates the distances.
*/
@objc public init(approximate: Bool = false) {
approx = approximate
self.approx = approximate
super.init()
numberFormatter.locale = .nationalizedCurrent
}

public required init?(coder decoder: NSCoder) {
approx = decoder.decodeBool(forKey: "approximate")
self.approx = decoder.decodeBool(forKey: "approximate")
super.init(coder: decoder)
}

override open func encode(with aCoder: NSCoder) {
super.encode(with: aCoder)
aCoder.encode(approx, forKey: "approximate")
aCoder.encode(self.approx, forKey: "approximate")
}

func threshold(for distance: CLLocationDistance) -> RoundingTable.Threshold {
if NavigationSettings.shared.usesMetric {
roundingTableMetric.threshold(for: distance)
self.roundingTableMetric.threshold(for: distance)
} else if numberFormatter.locale.identifier == "en-GB" {
roundingTableUK.threshold(for: distance)
self.roundingTableUK.threshold(for: distance)
} else {
roundingTableImperial.threshold(for: distance)
self.roundingTableImperial.threshold(for: distance)
}
}

Expand All @@ -188,21 +188,21 @@ open class DistanceFormatter: LengthFormatter {
@objc public func string(from distance: CLLocationDistance) -> String {
numberFormatter.positivePrefix = ""
numberFormatter.positiveSuffix = ""
numberFormatter.decimalSeparator = nonFractionalLengthFormatter.numberFormatter.decimalSeparator
numberFormatter.alwaysShowsDecimalSeparator = nonFractionalLengthFormatter.numberFormatter.alwaysShowsDecimalSeparator
numberFormatter.decimalSeparator = self.nonFractionalLengthFormatter.numberFormatter.decimalSeparator
numberFormatter.alwaysShowsDecimalSeparator = self.nonFractionalLengthFormatter.numberFormatter.alwaysShowsDecimalSeparator
numberFormatter.usesSignificantDigits = false
return formattedDistance(distance)
return self.formattedDistance(distance)
}

@objc override open func string(fromMeters numberInMeters: Double) -> String {
string(from: numberInMeters)
self.string(from: numberInMeters)
}

func formattedDistance(_ distance: CLLocationDistance) -> String {
let threshold = threshold(for: distance)
numberFormatter.maximumFractionDigits = threshold.maximumFractionDigits
numberFormatter.roundingIncrement = threshold.roundingIncrement as NSNumber
unit = threshold.unit
self.unit = threshold.unit
return threshold.localizedDistanceString(for: distance, using: self)
}

Expand All @@ -212,7 +212,7 @@ open class DistanceFormatter: LengthFormatter {
let threshold = threshold(for: distance)
numberFormatter.maximumFractionDigits = threshold.maximumFractionDigits
numberFormatter.roundingIncrement = threshold.roundingIncrement as NSNumber
unit = threshold.unit
self.unit = threshold.unit
return threshold.measurement(for: distance)
}

Expand All @@ -228,7 +228,7 @@ open class DistanceFormatter: LengthFormatter {

let string = string(from: distance)
let attributedString = NSMutableAttributedString(string: string, attributes: attrs)
let convertedDistance = distance.converted(to: threshold(for: distance).unit)
let convertedDistance = distance.converted(to: self.threshold(for: distance).unit)
if let quantityString = numberFormatter.string(from: convertedDistance as NSNumber) {
// NSMutableAttributedString methods accept NSRange, not Range.
let quantityRange = (string as NSString).range(of: quantityString)
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/NavigationLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
open class NavigationLocationManager: CLLocationManager, NSCopying {
public func copy(with zone: NSZone? = nil) -> Any {
let copy = NavigationLocationManager()
copy.lastKnownLocation = lastKnownLocation
copy.lastKnownLocation = self.lastKnownLocation
return copy
}

Expand Down
6 changes: 3 additions & 3 deletions MapboxCoreNavigation/NavigationSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class NavigationSettings: NSObject {
@objc public dynamic var distanceUnit: LengthFormatter.Unit = Locale.current.usesMetric ? .kilometer : .mile

var usesMetric: Bool {
switch distanceUnit {
switch self.distanceUnit {
case .kilometer:
true
case .mile:
Expand All @@ -61,7 +61,7 @@ public class NavigationSettings: NSObject {

override init() {
super.init()
for property in properties {
for property in self.properties {
guard let key = property.label else { continue }
let val = UserDefaults.standard.object(forKey: key.prefixed) ?? value(forKey: key)
setValue(val, forKey: key)
Expand All @@ -79,7 +79,7 @@ public class NavigationSettings: NSObject {
override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
var found = false

for property in properties {
for property in self.properties {
guard let key = property.label else { continue }

if key == keyPath {
Expand Down
28 changes: 14 additions & 14 deletions MapboxCoreNavigation/ReplayLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class ReplayLocationManager: NavigationLocationManager {
*/
@objc public var locations: [CLLocation]! {
didSet {
currentIndex = 0
self.currentIndex = 0
}
}

Expand All @@ -40,34 +40,34 @@ open class ReplayLocationManager: NavigationLocationManager {
}

override open func startUpdatingLocation() {
startDate = Date()
tick()
self.startDate = Date()
self.tick()
}

override open func stopUpdatingLocation() {
startDate = nil
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(tick), object: nil)
self.startDate = nil
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(self.tick), object: nil)
}

@objc fileprivate func tick() {
guard let startDate else { return }
let location = locations[currentIndex]
let location = self.locations[self.currentIndex]
lastKnownLocation = location
delegate?.locationManager?(self, didUpdateLocations: [location])
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(tick), object: nil)
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(self.tick), object: nil)

if currentIndex < locations.count - 1 {
let nextLocation = locations[currentIndex + 1]
let interval = nextLocation.timestamp.timeIntervalSince(location.timestamp) / TimeInterval(speedMultiplier)
if self.currentIndex < self.locations.count - 1 {
let nextLocation = self.locations[self.currentIndex + 1]
let interval = nextLocation.timestamp.timeIntervalSince(location.timestamp) / TimeInterval(self.speedMultiplier)
let intervalSinceStart = Date().timeIntervalSince(startDate) + interval
let actualInterval = nextLocation.timestamp.timeIntervalSince(locations.first!.timestamp)
let actualInterval = nextLocation.timestamp.timeIntervalSince(self.locations.first!.timestamp)
let diff = min(max(0, intervalSinceStart - actualInterval), 0.9) // Don't try to resync more than 0.9 seconds per location update
let syncedInterval = interval - diff

perform(#selector(tick), with: nil, afterDelay: syncedInterval)
currentIndex += 1
perform(#selector(self.tick), with: nil, afterDelay: syncedInterval)
self.currentIndex += 1
} else {
currentIndex = 0
self.currentIndex = 0
}
}
}
Loading

0 comments on commit ba33a72

Please sign in to comment.