Skip to content

Files

Latest commit

 

History

History
68 lines (29 loc) · 828 Bytes

implicitly_unwrapped_optional.md

File metadata and controls

68 lines (29 loc) · 828 Bytes

Pattern: Use of implicitly unwrapped optional

Issue: -

Description

Implicitly unwrapped optionals should be avoided when possible.

Examples of correct code:

@IBOutlet private var label: UILabel!


@IBOutlet var label: UILabel!


@IBOutlet var label: [UILabel!]


if !boolean {}


let int: Int? = 42


let int: Int? = nil

Examples of incorrect code:

let label: UILabel!


let IBOutlet: UILabel!


let labels: [UILabel!]


var ints: [Int!] = [42, nil, 42]


let label: IBOutlet!


let int: Int! = 42


let int: Int! = nil


var int: Int! = 42


let int: ImplicitlyUnwrappedOptional<Int>


let collection: AnyCollection<Int!>


func foo(int: Int!) {}

Further Reading