swiftlint
Difference between NSRange and NSMakeRange
The only difference between them is that NSRange(location: 0, length: 5) is an initializer for NSRange while NSMakeRange(0, 5) is a function which creates a new NSRange instance (by using the same initializer inside most likely) and actually is redundant in Swift. Swift has simply inherited it from Objective-C. I would stick to the former
Cyclomatic Complexity Violation: Function should have complexity 10 or less: currently complexity equals 13 (cyclomatic_complexity)
The method is too complex. But instead of rewriting the code, you could exclude switches from the cyclomatic_complexity calculation (since they are perfectly readable) like this: cyclomatic_complexity: ignores_case_statements: true
How do I create .swiftlint.yml file & where I need to put it?
If you are using the terminal: cd your_project_directory touch .swiftlint.yml
Swiftlint can’t be found on Apple Silicon xcode
I was unable to find how to modify the $PATH variable for Xcode build phase scripts permanently. This script will add the Apple Silicon homebrew path to your scripts PATH for the duration of the run. I’ve tested this on an M1 and Intel Mac and it works for both. # Adds support for Apple … Read more
Swiftlint warning : For Where Violation: `where` clauses are preferred over a single `if` inside a `for`. (for_where)
The syntax preferred by your swiftlint configuration is: for settingsKeys in searchResults where settingsKeys.key == settingsObject.key { settingsKeys.value = settingsObject.value try context.save() } Which is the similar to for settingsKeys in (searchResults.filter { $0.key == settingsObject.key }) { settingsKeys.value = settingsObject.value try context.save() } If you know there is only one result with the same … Read more
“${PODS_ROOT}/SwiftLint/swiftlint” causes “Command PhaseScriptExecution failed with a nonzero exit code” with Xcode 10
Its because of Keychain Access. Open Keychain Access Right Click Login Tab Lock Keychain Login Right Click Login Tab again Unlock Keychain Login and problem solved 🙂
SwiftLint: Exclude file for specific rule
Well, if you don’t want some specific rules to be applied to a specific file you can use the technique mentioned by @Benno Kress. For that you need to add a comment in your swift file as given below. The rules will be disabled until the end of the file or until the linter sees … Read more