Explicit Init
Explicitly calling .init() should be avoided
- Identifier:
explicit_init
- Enabled by default: No
- Supports autocorrection: Yes
- Kind: idiomatic
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning include_bare_init false
Non Triggering Examples
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) }
Observable.zip(obs1, obs2, resultSelector: MyType.init).asMaybe()
_ = GleanMetrics.Tabs.someType.init()
Observable.zip(
obs1,
obs2,
resultSelector: MyType.init
).asMaybe()
Triggering Examples
[1].flatMap{String↓.init($0)}
[String.self].map { Type in Type↓.init(1) }
func foo() -> [String] {
return [1].flatMap { String↓.init($0) }
}
_ = GleanMetrics.Tabs.GroupedTabExtra↓.init()
_ = Set<KsApi.Category>↓.init()
Observable.zip(
obs1,
obs2,
resultSelector: { MyType↓.init($0, $1) }
).asMaybe()