Skip to content

Latest commit

 

History

History
38 lines (19 loc) · 636 Bytes

explicit_init.md

File metadata and controls

38 lines (19 loc) · 636 Bytes

Pattern: Use of explicit .init()

Issue: -

Description

Explicitly calling .init() should be avoided.

Examples of correct code:

import Foundation; class C: NSObject { override init() { super.init() }}


struct S { let n: Int }; extension S { init() { self.init(n: 1) } }


[1].flatMap(String.init)


[String.self].map { $0.init(1) }


[String.self].map { type in type.init(1) }

Examples of incorrect code:

[1].flatMap{String.init($0)}


[String.self].map { Type in Type.init(1) }

Further Reading