ControlRoom icon indicating copy to clipboard operation
ControlRoom copied to clipboard

SwiftLint warnings - more subtle fixes required

Open sbeitzel opened this issue 8 months ago • 0 comments

If there were a label, "question" or "needs guidance" that would totally apply here. I'm trying to clean up all the SwiftLint warnings about the code and, having taken care of the very easy whitespace and redundant initializer warnings, here's what's left:

(Using Xcode Version 16.3 (16E140), macOS 15.3.2 (24D81), on an M1 MacBook Pro)

/Users/sbeitzel/src/github/ControlRoom/ControlRoom/Simulator UI/ControlScreens/AppView/NotificationEditorView.swift:31:34: Non-optional String -> Data Conversion Violation: Prefer non-optional `Data(_:)` initializer when converting `String` to `Data` (non_optional_string_data_conversion)

/Users/sbeitzel/src/github/ControlRoom/ControlRoom/Helpers/XcodeHelper.swift:16:26: Optional Data -> String Conversion Violation: Prefer failable `String(bytes:encoding:)` initializer when converting `Data` to `String` (optional_data_string_conversion)

/Users/sbeitzel/src/github/ControlRoom/ControlRoom/Controllers/LocalSearchController.swift:118:10: Main actor-isolated instance method 'completerDidUpdateResults' cannot be used to satisfy nonisolated requirement from protocol 'MKLocalSearchCompleterDelegate'; this is an error in the Swift 6 language mode

/Users/sbeitzel/src/github/ControlRoom/ControlRoom/Controllers/LocalSearchController.swift:127:10: Main actor-isolated instance method 'completer(_:didFailWithError:)' cannot be used to satisfy nonisolated requirement from protocol 'MKLocalSearchCompleterDelegate'; this is an error in the Swift 6 language mode

/Users/sbeitzel/src/github/ControlRoom/ControlRoom/Extensions/CLLocationCoordinate2D-Identifiable.swift:12:1: Extension declares a conformance of imported type 'CLLocationCoordinate2D' to imported protocol 'Identifiable'; this will not behave correctly if the owners of 'CoreLocation' introduce this conformance in the future
  • So, the non_optional_string_data_conversion and optional_data_string_conversion warnings strike me as a stylistic choice. These rules are enabled by default with SwiftLint, but I feel like this doesn't really have a performance impact -- it's just down to code readability. I've noticed that in lots of examples I've seen on HWS+ over the years Paul has consistently ignored this particular pattern. So, would we like to rewrite the code so as not to trigger the warnings, or should we suppress them?
  • The warnings about main actor-isolated methods not satisfying the non-isolated protocol requirement are more troubling. When I run the application with the debugger, I do get a purple warning in a different place about some observation/publisher problems so I know that the code isn't immune to that class of issue.
Publishing changes from within view updates is not allowed, this will cause undefined behavior.

sbeitzel avatar Apr 24 '25 03:04 sbeitzel