Skip to content

Commit

Permalink
fixed the large majority of the swiftlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
merlos committed Jun 1, 2023
1 parent 214e15f commit ad594e3
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
if gpxFilesFound {
for index in 0..<fileTable.numberOfRows {
guard let cell = fileTable.rowController(at: index) as? GPXFileTableRowController else { continue }
// swiftlint:disable force_cast
// swiftlint:disable:next force_cast
let gpxFileInfo = fileList.object(at: index) as! GPXFileInfo
cell.fileLabel.setText(gpxFileInfo.fileName)
}
Expand Down Expand Up @@ -232,7 +232,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
self.hideProgressIndicators()
return
}
// swiftlint:disable force_cast
// swiftlint:disable:next force_cast
let gpxFileInfo = fileList.object(at: rowIndex) as! GPXFileInfo
self.scroll(to: progressGroup, at: .top, animated: true) // scrolls to top when indicator is shown.
self.updateProgressIndicators(status: .sending, fileName: gpxFileInfo.fileName)
Expand All @@ -257,7 +257,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
}
GPXFileManager.removeFileFromURL(fileURL)

//Delete from list and Table
// Delete from list and Table
fileList.removeObject(at: rowIndex)

}
Expand Down
57 changes: 21 additions & 36 deletions OpenGpxTracker-Watch Extension/InterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MapKit
import CoreLocation
import CoreGPX

//Button colors
// Button colors
let kPurpleButtonBackgroundColor: UIColor = UIColor(red: 146.0/255.0, green: 166.0/255.0, blue: 218.0/255.0, alpha: 0.90)
let kGreenButtonBackgroundColor: UIColor = UIColor(red: 142.0/255.0, green: 224.0/255.0, blue: 102.0/255.0, alpha: 0.90)
let kRedButtonBackgroundColor: UIColor = UIColor(red: 244.0/255.0, green: 94.0/255.0, blue: 94.0/255.0, alpha: 0.90)
Expand All @@ -20,7 +20,7 @@ let kDisabledBlueButtonBackgroundColor: UIColor = UIColor(red: 74.0/255.0, green
let kDisabledRedButtonBackgroundColor: UIColor = UIColor(red: 244.0/255.0, green: 94.0/255.0, blue: 94.0/255.0, alpha: 0.10)
let kWhiteBackgroundColor: UIColor = UIColor(red: 254.0/255.0, green: 254.0/255.0, blue: 254.0/255.0, alpha: 0.90)

//Accesory View buttons tags
// Accesory View buttons tags
let kDeleteWaypointAccesoryButtonTag = 666
let kEditWaypointAccesoryButtonTag = 333

Expand Down Expand Up @@ -70,7 +70,7 @@ class InterfaceController: WKInterfaceController {
manager.requestAlwaysAuthorization()

manager.desiredAccuracy = kCLLocationAccuracyBest
manager.distanceFilter = 2 //meters
manager.distanceFilter = 2 // meters
manager.allowsBackgroundLocationUpdates = true
return manager
}()
Expand All @@ -81,10 +81,10 @@ class InterfaceController: WKInterfaceController {
/// Underlying class that handles background stuff
let map = GPXMapView() // not even a map view. Considering renaming

//Status Vars
// Status Vars
var stopWatch = StopWatch()
var lastGpxFilename: String = ""
var wasSentToBackground: Bool = false //Was the app sent to background
var wasSentToBackground: Bool = false // Was the app sent to background
var isDisplayingLocationServicesDenied: Bool = false

/// Does the 'file' have any waypoint?
Expand Down Expand Up @@ -130,36 +130,24 @@ class InterfaceController: WKInterfaceController {
// set Tracker button to allow Start
trackerButton.setTitle(NSLocalizedString("START_TRACKING", comment: "no comment"))
trackerButton.setBackgroundColor(kGreenButtonBackgroundColor)
//save & reset button to transparent.
// Save & reset button to transparent.
saveButton.setBackgroundColor(kDisabledBlueButtonBackgroundColor)
resetButton.setBackgroundColor(kDisabledRedButtonBackgroundColor)
//reset clock
// Reset clock
stopWatch.reset()
timeLabel.setText(stopWatch.elapsedTimeString)

map.reset() //reset gpx logging
lastGpxFilename = "" //clear last filename, so when saving it appears an empty field
map.reset() // Reset gpx logging
lastGpxFilename = "" // Clear last filename, so when saving it appears an empty field

totalTrackedDistanceLabel.setText(map.totalTrackedDistance.toDistance(useImperial: preferences.useImperial))

//currentSegmentDistanceLabel.distance = (map.currentSegmentDistance)

/*
// XXX Left here for reference
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.trackerButton.hidden = true
self.pauseButton.hidden = false
}, completion: {(f: Bool) -> Void in
println("finished animation start tracking")
})
*/


case .tracking:
print("switched to tracking mode")
// set trackerButton to allow Pause
trackerButton.setTitle(NSLocalizedString("PAUSE", comment: "no comment"))
trackerButton.setBackgroundColor(kPurpleButtonBackgroundColor)
//activate save & reset buttons
// Activate save & reset buttons
saveButton.setBackgroundColor(kBlueButtonBackgroundColor)
resetButton.setBackgroundColor(kRedButtonBackgroundColor)
// start clock
Expand All @@ -173,7 +161,7 @@ class InterfaceController: WKInterfaceController {
// activate save & reset (just in case switched from .NotStarted)
saveButton.setBackgroundColor(kBlueButtonBackgroundColor)
resetButton.setBackgroundColor(kRedButtonBackgroundColor)
//pause clock
// Pause clock
self.stopWatch.stop()
// start new track segment
self.map.startNewTrackSegment()
Expand All @@ -182,7 +170,7 @@ class InterfaceController: WKInterfaceController {
}

/// Editing Waypoint Temporal Reference
var lastLocation: CLLocation? //Last point of current segment.
var lastLocation: CLLocation? // Last point of current segment.

override func awake(withContext context: Any?) {
print("InterfaceController:: awake")
Expand Down Expand Up @@ -242,7 +230,7 @@ class InterfaceController: WKInterfaceController {
case .tracking:
gpxTrackingStatus = .paused
case .paused:
//set to tracking
// Set to tracking
gpxTrackingStatus = .tracking
}

Expand Down Expand Up @@ -279,7 +267,7 @@ class InterfaceController: WKInterfaceController {
let gpxString = self.map.exportToGPXString()
GPXFileManager.save(filename, gpxContents: gpxString)
self.lastGpxFilename = filename
//print(gpxString)
// print(gpxString)

/// Just a 'done' button, without
let action = WKAlertAction(title: "Done", style: .default) {}
Expand Down Expand Up @@ -330,19 +318,19 @@ class InterfaceController: WKInterfaceController {
func checkLocationServicesStatus() {
let authorizationStatus = CLLocationManager.authorizationStatus()

//Has the user already made a permission choice?
// Has the user already made a permission choice?
guard authorizationStatus != .notDetermined else {
//We should take no action until the user has made a choice
// We should take no action until the user has made a choice
return
}

//Does the app have permissions to use the location servies?
// Does the app have permissions to use the location servies?
guard [.authorizedAlways, .authorizedWhenInUse ].contains(authorizationStatus) else {
displayLocationServicesDeniedAlert()
return
}

//Are location services enabled?
// Are location services enabled?
guard CLLocationManager.locationServicesEnabled() else {
displayLocationServicesDisabledAlert()
return
Expand Down Expand Up @@ -408,8 +396,6 @@ extension InterfaceController: CLLocationManagerDelegate {
altitudeLabel.setText(kUnknownAltitudeText)
signalImageView.setImage(signalImage0)
speedLabel.setText(kUnknownSpeedText)
//signalAccuracyLabel.text = kUnknownAccuracyText
//signalImageView.image = signalImage0
let locationError = error as? CLError
switch locationError?.code {
case CLError.locationUnknown:
Expand All @@ -430,7 +416,7 @@ extension InterfaceController: CLLocationManagerDelegate {
///
///
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//updates signal image accuracy
// Updates signal image accuracy
let newLocation = locations.first!

let hAcc = newLocation.horizontalAccuracy
Expand Down Expand Up @@ -461,14 +447,13 @@ extension InterfaceController: CLLocationManagerDelegate {
coordinatesLabel.setText("\(latFormat),\(lonFormat)")
altitudeLabel.setText(newLocation.altitude.toAltitude(useImperial: preferences.useImperial))

//Update speed (provided in m/s, but displayed in km/h)
// Update speed (provided in m/s, but displayed in km/h)
speedLabel.setText(newLocation.speed.toSpeed(useImperial: preferences.useImperial))

if gpxTrackingStatus == .tracking {
print("didUpdateLocation: adding point to track (\(newLocation.coordinate.latitude),\(newLocation.coordinate.longitude))")
map.addPointToCurrentTrackSegmentAtLocation(newLocation)
totalTrackedDistanceLabel.setText(map.totalTrackedDistance.toDistance(useImperial: preferences.useImperial))
//currentSegmentDistanceLabel.distance = map.currentSegmentDistance
}
}
}
7 changes: 3 additions & 4 deletions OpenGpxTracker/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class AboutViewController: UIViewController {

self.title = NSLocalizedString("ABOUT", comment: "no comment")

//Add the done button
// Add the done button
let shareItem = UIBarButtonItem(title: NSLocalizedString("DONE", comment: "no comment"),
style: UIBarButtonItem.Style.plain, target: self,
action: #selector(AboutViewController.closeViewController))
self.navigationItem.rightBarButtonItems = [shareItem]

//Add the Webview
// Add the Webview
self.webView = WKWebView(frame: self.view.frame, configuration: WKWebViewConfiguration())

self.webView?.navigationDelegate = self
Expand Down Expand Up @@ -82,8 +82,7 @@ extension AboutViewController: WKNavigationDelegate {
if navigationAction.navigationType == .linkActivated {
if #available(iOS 10, *) {
UIApplication.shared.open(navigationAction.request.url!)
}
else {
} else {
UIApplication.shared.openURL(navigationAction.request.url!)
}
print("AboutViewController: external link sent to Safari")
Expand Down
5 changes: 2 additions & 3 deletions OpenGpxTracker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
//self.saveContext()
// self.saveContext()
}

/// Default pandle load GPX file
Expand Down Expand Up @@ -211,9 +211,8 @@ extension AppDelegate: WCSessionDelegate {
/// Called when a file is received from Apple Watch.
/// Displays a popup informing about the reception of the file.
func session(_ session: WCSession, didReceive file: WCSessionFile) {
// swiftlint:disable force_cast
// swiftlint:disable:next force_cast
let fileName = file.metadata!["fileName"] as! String?

DispatchQueue.global().sync {
GPXFileManager.moveFrom(file.fileURL, fileName: fileName)
print("ViewController:: Received file from WatchConnectivity Session")
Expand Down
4 changes: 3 additions & 1 deletion OpenGpxTracker/CoreDataHelper+FetchRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extension CoreDataHelper {
self.lastFileName = safePoint.lastFileName ?? ""
self.lastTracksegmentId = safePoint.lastTrackSegmentId
self.isContinued = safePoint.continuedAfterSave
print("Core Data Helper: fetched CDRoot lastFileName:\(self.lastFileName) lastTracksegmentId: \(self.lastTracksegmentId) isContinued: \(self.isContinued)")
// swiftlint:disable:next line_length
print("Core Data Helper: fetched CDRoot lastFileName:\(self.lastFileName) lastTracksegmentId: \(self.lastTracksegmentId) isContinued: \(self.isContinued)")
}
}
return asyncRootFetchRequest
Expand Down Expand Up @@ -70,6 +71,7 @@ extension CoreDataHelper {
}
self.trackpointId = trackPointResults.last?.trackpointId ?? Int64()
self.tracksegments.append(self.currentSegment)
// siftlint:disable:next line_length
print("Core Data Helper: fetched CDTrackpoints. # of tracksegments: \(self.tracksegments.count). trackPointId: \(self.trackpointId) trackSegmentId: \(self.tracksegmentId)")
}
}
Expand Down
21 changes: 7 additions & 14 deletions OpenGpxTracker/CoreDataHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class CoreDataHelper {
// MARK: Other Declarations

/// app delegate.
// swiftlint:disable force_cast
let appDelegate = UIApplication.shared.delegate as! AppDelegate

// swiftlint:disable:previous force_cast
// arrays for handling retrieval of data when needed.

// recovered tracksegments
Expand Down Expand Up @@ -65,8 +64,8 @@ class CoreDataHelper {
childManagedObjectContext.parent = appDelegate.managedObjectContext

childManagedObjectContext.perform {
// swiftlint:disable:next force_cast
let root = NSEntityDescription.insertNewObject(forEntityName: "CDRoot", into: childManagedObjectContext) as! CDRoot

root.lastFileName = lastFileName
root.continuedAfterSave = willContinue
root.lastTrackSegmentId = self.tracksegmentId
Expand Down Expand Up @@ -101,7 +100,7 @@ class CoreDataHelper {

childManagedObjectContext.perform {
print("Core Data Helper: Add trackpoint with id: \(self.trackpointId)")
// swiftlint:disable force_cast
// swiftlint:disable:next force_cast
let pt = NSEntityDescription.insertNewObject(forEntityName: "CDTrackpoint", into: childManagedObjectContext) as! CDTrackpoint

guard let elevation = trackpoint.elevation else { return }
Expand Down Expand Up @@ -153,9 +152,8 @@ class CoreDataHelper {

waypointChildManagedObjectContext.perform {
print("Core Data Helper: Add waypoint with id: \(self.waypointId)")
// swiftlint:disable force_cast
// swiftlint:disable:next force_cast
let pt = NSEntityDescription.insertNewObject(forEntityName: "CDWaypoint", into: waypointChildManagedObjectContext) as! CDWaypoint

guard let latitude = waypoint.latitude else { return }
guard let longitude = waypoint.longitude else { return }

Expand Down Expand Up @@ -252,7 +250,6 @@ class CoreDataHelper {
print("Failure to update and save waypoint to context at child context: \(error)")
}
}

}

do {
Expand Down Expand Up @@ -332,7 +329,6 @@ class CoreDataHelper {

/// Delete all objects of entity given as parameter in Core Data.
func coreDataDeleteAll<T: NSManagedObject>(of type: T.Type) {

print("Core Data Helper: Batch Delete \(T.self) from Core Data")

if #available(iOS 10.0, *) {
Expand Down Expand Up @@ -372,7 +368,7 @@ class CoreDataHelper {
// generates a GPXRoot from recovered data
if self.isContinued && self.tracksegments.count >= (self.lastTracksegmentId + 1) {

//Check if there was a tracksegment
// Check if there was a tracksegment
if root.tracks.last?.segments.count == 0 {
root.tracks.last?.add(trackSegment: GPXTrackSegment())
}
Expand All @@ -389,7 +385,8 @@ class CoreDataHelper {
DispatchQueue.main.sync {
NotificationCenter.default.post(name: .loadRecoveredFile, object: nil,
userInfo: ["recoveredRoot": root, "fileName": self.lastFileName])
let toastMessage = NSLocalizedString("LAST_SESSION_LOADED", comment: "the filename displayed after the text") + " \n" + self.lastFileName + ".gpx"
let toastMessage = NSLocalizedString("LAST_SESSION_LOADED",
comment: "the filename displayed after the text") + " \n" + self.lastFileName + ".gpx"
Toast.regular(toastMessage, position: .top)
}
} else {
Expand Down Expand Up @@ -425,7 +422,6 @@ class CoreDataHelper {
// clear aft save.
self.clearAll()
self.coreDataDeleteAll(of: CDRoot.self)
//self.deleteCDRootFromCoreData()
}

// MARK: Reset & Clear
Expand All @@ -438,7 +434,6 @@ class CoreDataHelper {
self.trackpointId = 0
self.waypointId = 0
self.tracksegmentId = 0

}

/// Clear all arrays and current segment after recovery.
Expand Down Expand Up @@ -477,7 +472,5 @@ class CoreDataHelper {

// reset order sorting ids
self.resetIds()

}

}
1 change: 0 additions & 1 deletion OpenGpxTracker/DefaultDateFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class DefaultDateFormat {

/// Returns sample date time based on user input.
func getDate(processedFormat dateFormat: String, useUTC: Bool = false, useENLocale: Bool = false) -> String {
//processedDateFormat = DefaultDateFormat.getDateFormat(unprocessed: self.cellTextField.text!)
dateFormatter.dateFormat = dateFormat
dateFormatter.timeZone = useUTC ? TimeZone(secondsFromGMT: 0) : TimeZone.current
dateFormatter.locale = useENLocale ? Locale(identifier: "en_US_POSIX") : Locale.current
Expand Down
Loading

0 comments on commit ad594e3

Please sign in to comment.