A Swift Macro that adds an unimplemented init(coder:)
to your classes so that you don’t have to.
NoCoderInitMacro is installable using Swift Package Manager.
Add to your package.swift
.package(url: "https://github.com/mikeyclarke/NoCoderInitMacro.git", from: "1.0.0"),
Or through the Xcode UI:
- “Add Package Dependency…” (currently available from the File menu or in the right-click menu in the File Navigator)
- Enter the URL of this repository:
https://github.com/mikeyclarke/NoCoderInitMacro.git
- Choose "Up To Next Major Version": 1.0.0
Import the macro and then simply annotate any class that needs an init(coder:)
with @NoCoderInit
.
import NoCoderInitMacro
@NoCoderInit
class ViewController: PlatformViewController {
init() {
// …
}
}
// Expands to:
class ViewController: PlatformViewController {
init() {
// …
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
There are various alternatives to adding the unimplemented initializer.
NoCoderInitMacro is available under the MIT license. See LICENSE for details.