Force Unwrapping

Force unwrapping should be avoided

  • Identifier: force_unwrapping
  • 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

if let url = NSURL(string: query)
navigationController?.pushViewController(viewController, animated: true)
let s as! Test
try! canThrowErrors()
let object: Any!
@IBOutlet var constraints: [NSLayoutConstraint]!
setEditing(!editing, animated: true)
navigationController.setNavigationBarHidden(!navigationController.navigationBarHidden, animated: true)
if addedToPlaylist && (!self.selectedFilters.isEmpty || self.searchBar?.text?.isEmpty == false) {}
print("\(xVar)!")
var test = (!bar)
var a: [Int]!
private var myProperty: (Void -> Void)!
func foo(_ options: [AnyHashable: Any]!) {
func foo() -> [Int]!
func foo() -> [AnyHashable: Any]!
func foo() -> [Int]! { return [] }
return self

Triggering Examples

let url = NSURL(string: query)!
navigationController!.pushViewController(viewController, animated: true)
let unwrapped = optional!
return cell!
let url = NSURL(string: "http://www.google.com")!
let dict = ["Boooo": "👻"]
func bla() -> String {
    return dict["Boooo"]!
}
let dict = ["Boooo": "👻"]
func bla() -> String {
    return dict["Boooo"]!.contains("B")
}
let a = dict["abc"]!.contains("B")
dict["abc"]!.bar("B")
if dict["a"]!!!! {}
var foo: [Bool]! = dict["abc"]!
realm.objects(SwiftUTF8Object.self).filter("%K == %@", "柱нǢкƱаم👍", utf8TestString).first!
context("abc") {
  var foo: [Bool]! = dict["abc"]!
}
open var computed: String { return foo.bar! }
return self!
[1, 3, 5, 6].first { $0.isMultiple(of: 2) }!
map["a"]!!