Force Unwrapping

Force unwrapping should be avoided.

  • Identifier: force_unwrapping
  • Enabled by default: Disabled
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 3.0.0
  • Default configuration: 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"]!
context("abc") {
  var foo: [Bool]! = dict["abc"]!
}
open var computed: String { return foo.bar! }
return self!