SwiftLint
SwiftLint copied to clipboard
legacy_objc_type rule triggers on NSNumber in the context of NumberFormatter which requires it
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
Describe the bug
legacy_objc_type rule triggers on NSNumber in the context of NumberFormatter
Complete output when running SwiftLint, including the stack trace and command used
% swiftlint
Linting Swift files in current working directory
Linting
...
Linting
warning: Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
Done linting! Found 1 violation, 0 serious in files.
Environment
- SwiftLint version: 0.44.0
- Installation method used: Homebrew and SPM via Custom Package
- Paste your configuration file:
only_rules:
- legacy_objc_type
// This triggers a violation:
NumberFormatter.string(from: Double as NSNumber)
Originally posted by @PH9 in https://github.com/realm/SwiftLint/issues/3555#issuecomment-811875997
We recently ran into this as well with the following APIs.
In my opinion, there is nothing we can really do about that. When working with certain frameworks it is simply unavoidable to reference these types in some way. The rule is opt-in and can be disabled by comments in the code in case of (rare) exceptions.
I got an error for NSNumber violation so changed: NSNumber.init(value: someValue) to NSNumber.(value: someValue)
Worked !