Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
[TECH] Marked the "not implemented" initializers as "unavailable"
Browse files Browse the repository at this point in the history
When providing a custom initializer for subclasses of (mostly) UIKit
classes conforming to 'NSCoding' the required initializer must be
provided by those subclasses.

Most of them will never be used and stay with the auto suggestion
of Xcode causing a `fatalError`:

```
required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
```

As this should never be called, I marked those initializers
with `available(*, unavailable)`. Calling those initializers
will now fail at compile time instead of causing a
runtime crash.

Additionally, it will stop Xcode suggesting those initializers
as code completions.
  • Loading branch information
lennartstolz committed Jun 17, 2020
1 parent 5a9b43f commit eb036f8
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class DMConfigurationViewController: UITableViewController, RequiresAppDep
title = "⚙️ Configuration"
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down Expand Up @@ -131,6 +132,7 @@ private class DMConfigurationCell: UITableViewCell {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final class DMQRCodeScanViewController: UIViewController {
super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down Expand Up @@ -109,6 +110,7 @@ private final class DMQRCodeScanView: UIView {
videoPreviewLayer.session = captureSession
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class DMQRCodeViewController: UIViewController {
super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class DMSubmissionStateViewController: UITableViewController {
super.init(style: .plain)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final class DMViewController: UITableViewController {
title = "👩🏾‍💻🧑‍💻"
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down Expand Up @@ -261,6 +262,7 @@ private class KeyCell: UITableViewCell {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AppInformationLegalCell: UITableViewCell {
var licensorLabel = ENALabel()
var licenseLabel = ENALabel()

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DynamicTableViewHeaderImageView: UITableViewHeaderFooterView {
get { heightConstraint.constant }
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DynamicTableViewHeaderSeparatorView: UITableViewHeaderFooterView {
get { heightConstraint.constant }
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class ExposureNotificationSettingViewController: UITableViewController {
super.init(coder: coder)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ final class ExposureDetectionViewController: DynamicTableViewController, Require
super.init(coder: coder)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has intentionally not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ final class ExposureSubmissionNavigationController: UINavigationController, UINa
self.testResult = testResult
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ExposureSubmissionOverviewViewController: DynamicTableViewController, Spin
super.init(coder: aDecoder)
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class HomeViewController: UIViewController {
addToUpdatingSetIfNeeded(homeInteractor)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has intentionally not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class OnboardingInfoViewController: UIViewController {
super.init(coder: coder)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has intentionally not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NotificationSettingsViewController: UIViewController {
super.init(coder: coder)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class SettingsViewController: UITableViewController {
super.init(coder: coder)
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import UIKit

class SectionSystemBackgroundDecorationView: UICollectionReusableView {
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down

0 comments on commit eb036f8

Please sign in to comment.