Skip to content

Commit 773f3a3

Browse files
authored
Merge pull request #174 from NSMutableString/feature/fix-swiftlint-errors
Fix swiftlint build errors and a lot of warnings
2 parents 52a8988 + 11d5228 commit 773f3a3

36 files changed

+887
-1011
lines changed

OpenGpxTracker-Watch Extension/ComplicationController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import ClockKit
1010

11-
1211
class ComplicationController: NSObject, CLKComplicationDataSource {
1312

1413
// MARK: - Timeline Configuration
1514

16-
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
15+
func getSupportedTimeTravelDirections(for complication: CLKComplication,
16+
withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
1717
handler([.forward, .backward])
1818
}
1919

@@ -36,12 +36,14 @@ class ComplicationController: NSObject, CLKComplicationDataSource {
3636
handler(nil)
3737
}
3838

39-
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
39+
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int,
40+
withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
4041
// Call the handler with the timeline entries prior to the given date
4142
handler(nil)
4243
}
4344

44-
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
45+
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int,
46+
withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
4547
// Call the handler with the timeline entries after to the given date
4648
handler(nil)
4749
}

OpenGpxTracker-Watch Extension/ExtensionDelegate.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
1515
}
1616

1717
func applicationDidBecomeActive() {
18-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
18+
// Restart any tasks that were paused (or not yet started) while the application was inactive.
19+
// If the application was previously in the background, optionally refresh the user interface.
1920
}
2021

2122
func applicationWillResignActive() {
22-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
23+
// Sent when the application is about to move from active to inactive state.
24+
// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
25+
// or when the user quits the application and it begins the transition to the background state.
2326
// Use this method to pause ongoing tasks, disable timers, etc.
2427
}
2528

2629
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
27-
// Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one.
30+
// Sent when the system needs to launch the application in the background to process tasks.
31+
// Tasks arrive in a set, so loop through and process each one.
2832
for task in backgroundTasks {
2933
// Use a switch statement to check the task type
3034
switch task {

OpenGpxTracker-Watch Extension/GPXFileTableInterfaceController.swift

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,21 @@ class GPXFileTableInterfaceController: WKInterfaceController {
3737
var fileList: NSMutableArray = [kNoFiles]
3838

3939
/// Is there any GPX file in the directory?
40-
var gpxFilesFound = false;
40+
var gpxFilesFound = false
4141

4242
/// Temporary variable to manage
4343
var selectedRowIndex = -1
4444

4545
/// true if a gpx file will be sent.
4646
var willSendFile: Bool {
47-
get {
48-
return session?.outstandingFileTransfers.count != 0
49-
}
47+
return session?.outstandingFileTransfers.count != 0
5048
}
5149

5250
/// To ensure hide animation properly timed.
5351
var time = DispatchTime.now()
5452

5553
/// Watch communication session
56-
private let session : WCSession? = WCSession.isSupported() ? WCSession.default : nil
54+
private let session: WCSession? = WCSession.isSupported() ? WCSession.default: nil
5755

5856
override func awake(withContext context: Any?) {
5957
super.awake(withContext: context)
@@ -64,7 +62,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
6462
// MARK: Progress Indicators
6563

6664
/// States of sending files
67-
enum sendingStatus {
65+
enum SendingStatus {
6866
/// represents current state as sending
6967
case sending
7068
/// represents current state as successful
@@ -88,7 +86,8 @@ class GPXFileTableInterfaceController: WKInterfaceController {
8886
self.progressGroup.setHeight(0)
8987
})
9088
}
91-
// imageview do not have to be set with stop animating, as image indicator should already have been set as successful or failure image, which is static.
89+
// imageview do not have to be set with stop animating,
90+
// as image indicator should already have been set as successful or failure image, which is static.
9291
}
9392

9493
/// Displays progress indicators.
@@ -98,13 +97,13 @@ class GPXFileTableInterfaceController: WKInterfaceController {
9897
self.progressGroup.setHeight(30)
9998
self.progressGroup.setHidden(false)
10099
progressImageView.setImageNamed("Progress-")
101-
progressImageView.startAnimatingWithImages(in: NSMakeRange(0, 12), duration: 1, repeatCount: 0)
100+
progressImageView.startAnimatingWithImages(in: NSRange(location: 0, length: 12), duration: 1, repeatCount: 0)
102101
}
103102

104103
/// Updates progress indicators according to status when sending.
105104
///
106105
/// If status is success or failure, method will hide and animate progress indicators when done
107-
func updateProgressIndicators(status: sendingStatus, fileName: String?) {
106+
func updateProgressIndicators(status: SendingStatus, fileName: String?) {
108107
switch status {
109108
case .sending:
110109
progressTitle.setText(NSLocalizedString("SENDING", comment: "no comment"))
@@ -115,8 +114,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
115114
// if there are files pending for sending, filename will not be displayed with the name of file.
116115
if fileTransfersCount >= 1 {
117116
progressFileName.setText(String(format: NSLocalizedString("X_FILES", comment: "no comment"), fileTransfersCount + 1))
118-
}
119-
else {
117+
} else {
120118
progressFileName.setText(fileName)
121119
}
122120

@@ -144,8 +142,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
144142

145143
if willSendFile == true {
146144
self.showProgressIndicators()
147-
}
148-
else {
145+
} else {
149146
self.hideProgressIndicators()
150147
}
151148

@@ -179,11 +176,11 @@ class GPXFileTableInterfaceController: WKInterfaceController {
179176
if gpxFilesFound {
180177
for index in 0..<fileTable.numberOfRows {
181178
guard let cell = fileTable.rowController(at: index) as? GPXFileTableRowController else { continue }
179+
// swiftlint:disable force_cast
182180
let gpxFileInfo = fileList.object(at: index) as! GPXFileInfo
183181
cell.fileLabel.setText(gpxFileInfo.fileName)
184182
}
185-
}
186-
else {
183+
} else {
187184
guard let cell = fileTable.rowController(at: 0) as? GPXFileTableRowController else { return }
188185
cell.fileLabel.setText(kNoFiles)
189186
}
@@ -217,15 +214,16 @@ class GPXFileTableInterfaceController: WKInterfaceController {
217214
/// Array of all available options
218215
let options = [shareOption, cancelOption, deleteOption]
219216

220-
presentAlert(withTitle: NSLocalizedString("FILE_SELECTED_TITLE", comment: "no comment"), message: NSLocalizedString("FILE_SELECTED_MESSAGE", comment: "no comment"), preferredStyle: .actionSheet, actions: options)
217+
presentAlert(withTitle: NSLocalizedString("FILE_SELECTED_TITLE", comment: "no comment"),
218+
message: NSLocalizedString("FILE_SELECTED_MESSAGE", comment: "no comment"),
219+
preferredStyle: .actionSheet, actions: options)
221220
}
222221
}
223222

224223
//
225224
// MARK: Action Sheet - Actions
226225
//
227-
228-
226+
229227
/// Attempts to transfer file to iOS app
230228
func actionTransferFileAtIndex(_ rowIndex: Int) {
231229
session?.activate()
@@ -234,11 +232,12 @@ class GPXFileTableInterfaceController: WKInterfaceController {
234232
self.hideProgressIndicators()
235233
return
236234
}
235+
// swiftlint:disable force_cast
237236
let gpxFileInfo = fileList.object(at: rowIndex) as! GPXFileInfo
238237
self.scroll(to: progressGroup, at: .top, animated: true) // scrolls to top when indicator is shown.
239238
self.updateProgressIndicators(status: .sending, fileName: gpxFileInfo.fileName)
240239
DispatchQueue.global().async {
241-
self.session?.transferFile(fileURL, metadata: ["fileName" : "\(gpxFileInfo.fileName).gpx"])
240+
self.session?.transferFile(fileURL, metadata: ["fileName": "\(gpxFileInfo.fileName).gpx"])
242241
}
243242
}
244243

@@ -262,7 +261,6 @@ class GPXFileTableInterfaceController: WKInterfaceController {
262261
fileList.removeObject(at: rowIndex)
263262

264263
}
265-
266264

267265
override func didDeactivate() {
268266
// This method is called when watch view controller is no longer visible
@@ -271,26 +269,25 @@ class GPXFileTableInterfaceController: WKInterfaceController {
271269

272270
}
273271

274-
275-
// MARK:- WCSessionDelegate
272+
// MARK: WCSessionDelegate
276273

277274
///
278275
/// Handles all the file transfer to iOS app processes
279276
///
280277
extension GPXFileTableInterfaceController: WCSessionDelegate {
281278

282279
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
280+
let prefixText = "GPXFileTableInterfaceController:: activationDidCompleteWithActivationState:"
283281
switch activationState {
284282
case .activated:
285-
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: session activated")
283+
print("\(prefixText) session activated")
286284
case .inactive:
287-
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: session inactive")
285+
print("\(prefixText) session inactive")
288286
case .notActivated:
289-
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: session not activated, error:\(String(describing: error))")
287+
print("\(prefixText) session not activated, error:\(String(describing: error))")
290288

291289
default:
292-
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: default, error:\(String(describing: error))")
293-
break
290+
print("\(prefixText) default, error:\(String(describing: error))")
294291
}
295292
}
296293

@@ -312,7 +309,9 @@ extension GPXFileTableInterfaceController: WCSessionDelegate {
312309
// presents alert after 1.5s, with error message
313310
// MARK: "as CVarArg" was suggested by XCode and my intruduce a bug...
314311
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
315-
self.presentAlert(withTitle: NSLocalizedString("ERROR_OCCURED_TITLE", comment: "no comment"), message: String(format: NSLocalizedString("ERROR_OCCURED_MESSAGE", comment: "no comment"), error as CVarArg), preferredStyle: .alert, actions: [doneAction])
312+
self.presentAlert(withTitle: NSLocalizedString("ERROR_OCCURED_TITLE", comment: "no comment"),
313+
message: String(format: NSLocalizedString("ERROR_OCCURED_MESSAGE", comment: "no comment"), error as CVarArg),
314+
preferredStyle: .alert, actions: [doneAction])
316315
}
317316
}
318317

OpenGpxTracker-Watch Extension/InterfaceController.swift

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ let kSignalAccuracy3 = 51.0
4444
let kSignalAccuracy2 = 101.0
4545
let kSignalAccuracy1 = 201.0
4646

47-
4847
///
4948
/// Main View Controller of the Watch Application. It is loaded when the application is launched
5049
///
@@ -64,8 +63,7 @@ class InterfaceController: WKInterfaceController {
6463
@IBOutlet var coordinatesLabel: WKInterfaceLabel!
6564
@IBOutlet var altitudeLabel: WKInterfaceLabel!
6665
@IBOutlet var speedLabel: WKInterfaceLabel!
67-
68-
66+
6967
/// Location Manager
7068
let locationManager: CLLocationManager = {
7169
let manager = CLLocationManager()
@@ -185,13 +183,11 @@ class InterfaceController: WKInterfaceController {
185183

186184
/// Editing Waypoint Temporal Reference
187185
var lastLocation: CLLocation? //Last point of current segment.
188-
189-
186+
190187
override func awake(withContext context: Any?) {
191188
print("InterfaceController:: awake")
192189
super.awake(withContext: context)
193-
194-
190+
195191
totalTrackedDistanceLabel.setText( 0.00.toDistance(useImperial: preferences.useImperial))
196192

197193
if gpxTrackingStatus == .notStarted {
@@ -207,8 +203,7 @@ class InterfaceController: WKInterfaceController {
207203
signalImageView.setImage(signalImage0)
208204
}
209205
}
210-
211-
206+
212207
override func willActivate() {
213208
// This method is called when watch view controller is about to be visible to user
214209
print("InterfaceController:: willActivate")
@@ -233,9 +228,7 @@ class InterfaceController: WKInterfaceController {
233228
locationManager.stopUpdatingLocation()
234229
}
235230
}
236-
237-
238-
231+
239232
///
240233
/// Main Start/Pause Button was tapped.
241234
///
@@ -292,7 +285,7 @@ class InterfaceController: WKInterfaceController {
292285
let action = WKAlertAction(title: "Done", style: .default) {}
293286

294287
presentAlert(withTitle: NSLocalizedString("FILE_SAVED_TITLE", comment: "no comment"),
295-
message: "\(filename).gpx", preferredStyle: .alert, actions: [action])
288+
message: "\(filename).gpx", preferredStyle: .alert, actions: [action])
296289

297290
}
298291

@@ -304,8 +297,7 @@ class InterfaceController: WKInterfaceController {
304297
@IBAction func resetButtonTapped() {
305298
self.gpxTrackingStatus = .notStarted
306299
}
307-
308-
300+
309301
/// returns a string with the format of current date dd-MMM-yyyy-HHmm' (20-Jun-2018-1133)
310302
///
311303
func defaultFilename() -> String {
@@ -314,8 +306,7 @@ class InterfaceController: WKInterfaceController {
314306
print("fileName:" + dateFormatter.string(from: Date()))
315307
return dateFormatter.string(from: Date())
316308
}
317-
318-
309+
319310
///
320311
/// Checks the location services status
321312
/// - Are location services enabled (access to location device wide)? If not => displays an alert
@@ -346,10 +337,11 @@ class InterfaceController: WKInterfaceController {
346337
print("LocationServicesDisabledAlert: cancel pressed")
347338
}
348339

349-
presentAlert(withTitle: NSLocalizedString("LOCATION_SERVICES_DISABLED", comment: "no comment"), message: NSLocalizedString("ENABLE_LOCATION_SERVICES", comment: "no comment"), preferredStyle: .alert, actions: [button])
340+
presentAlert(withTitle: NSLocalizedString("LOCATION_SERVICES_DISABLED", comment: "no comment"),
341+
message: NSLocalizedString("ENABLE_LOCATION_SERVICES", comment: "no comment"),
342+
preferredStyle: .alert, actions: [button])
350343
}
351344

352-
353345
///
354346
/// Displays an alert that informs the user that access to location was denied for this app (other apps may have access).
355347
/// It also dispays a button allows the user to go to settings to activate the location.
@@ -362,7 +354,9 @@ class InterfaceController: WKInterfaceController {
362354
print("LocationServicesDeniedAlert: cancel pressed")
363355
}
364356

365-
presentAlert(withTitle: NSLocalizedString("ACCESS_TO_LOCATION_DENIED", comment: "no comment"), message: NSLocalizedString("ALLOW_LOCATION", comment: "no comment"), preferredStyle: .alert, actions: [button])
357+
presentAlert(withTitle: NSLocalizedString("ACCESS_TO_LOCATION_DENIED", comment: "no comment"),
358+
message: NSLocalizedString("ALLOW_LOCATION", comment: "no comment"),
359+
preferredStyle: .alert, actions: [button])
366360
}
367361

368362
}
@@ -383,7 +377,6 @@ extension InterfaceController: StopWatchDelegate {
383377

384378
// MARK: CLLocationManagerDelegate
385379

386-
387380
extension InterfaceController: CLLocationManagerDelegate {
388381

389382
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
@@ -417,9 +410,10 @@ extension InterfaceController: CLLocationManagerDelegate {
417410
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
418411
//updates signal image accuracy
419412
let newLocation = locations.first!
420-
print("didUpdateLocation: received \(newLocation.coordinate) hAcc: \(newLocation.horizontalAccuracy) vAcc: \(newLocation.verticalAccuracy) floor: \(newLocation.floor?.description ?? "''")")
421413

422414
let hAcc = newLocation.horizontalAccuracy
415+
let vAcc = newLocation.verticalAccuracy
416+
print("didUpdateLocation: received \(newLocation.coordinate) hAcc: \(hAcc) vAcc: \(vAcc) floor: \(newLocation.floor?.description ?? "''")")
423417

424418
signalAccuracyLabel.setText(hAcc.toAccuracy(useImperial: preferences.useImperial))
425419
if hAcc < kSignalAccuracy6 {
@@ -434,7 +428,7 @@ extension InterfaceController: CLLocationManagerDelegate {
434428
self.signalImageView.setImage(signalImage2)
435429
} else if hAcc < kSignalAccuracy1 {
436430
self.signalImageView.setImage(signalImage1)
437-
} else{
431+
} else {
438432
self.signalImageView.setImage(signalImage0)
439433
}
440434

@@ -455,6 +449,4 @@ extension InterfaceController: CLLocationManagerDelegate {
455449
//currentSegmentDistanceLabel.distance = map.currentSegmentDistance
456450
}
457451
}
458-
459452
}
460-

0 commit comments

Comments
 (0)