Legacy Objective-C Reference Type

Prefer Swift value types to bridged Objective-C reference types

  • Identifier: legacy_objc_type
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

var array = Array<Int>()
var calendar: Calendar? = nil
var formatter: NSDataDetector
var className: String = NSStringFromClass(MyClass.self)
_ = URLRequest.CachePolicy.reloadIgnoringLocalCacheData
_ = Notification.Name("com.apple.Music.playerInfo")

Triggering Examples

var array = NSArray()
var calendar: NSCalendar? = nil
_ = NSURLRequest.CachePolicy.reloadIgnoringLocalCacheData
_ = NSNotification.Name("com.apple.Music.playerInfo")
let keyValuePair: (Int) -> (NSString, NSString) = {
  let n = "\($0)" as NSString; return (n, n)
}
dictionary = [NSString: NSString](uniqueKeysWithValues:
  (1...10_000).lazy.map(keyValuePair))
extension Foundation.Notification.Name {
    static var reachabilityChanged: Foundation.NSNotification.Name {
        return Foundation.Notification.Name("org.wordpress.reachability.changed")
    }
}