Skip to content

Files

Latest commit

 

History

History
30 lines (17 loc) · 822 Bytes

compiler_protocol_init.md

File metadata and controls

30 lines (17 loc) · 822 Bytes

Pattern: Use of init(arrayLiteral:)

Issue: -

Description

Avoid calling this initializer directly. It is used by the compiler when you use an array literal. Instead, create a new set using an array literal as its value by enclosing a comma-separated list of values in square brackets. You can use an array literal anywhere a set is expected by the type context.

Examples of correct code:

let set: Set<Int> = [1, 2]


let set = Set(array)

Examples of incorrect code:

let set = Set(arrayLiteral: 1, 2)


let set = Set.init(arrayLiteral: 1, 2)

Further Reading