From dfd3ad4861177eab2a41fe59bb25491e0f8e7a14 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Thu, 29 Jun 2017 21:49:20 -0700 Subject: [PATCH] more swifty class handling --- Classes/Issues/IssuesViewController.swift | 24 +++++++------------ .../NotificationsViewController.swift | 10 ++++---- .../SegmentedControlSectionController.swift | 4 ++++ Classes/Settings/SettingsViewController.swift | 5 ++-- Resources/Info.plist | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Classes/Issues/IssuesViewController.swift b/Classes/Issues/IssuesViewController.swift index 2e7ea02d..c3b74ad0 100644 --- a/Classes/Issues/IssuesViewController.swift +++ b/Classes/Issues/IssuesViewController.swift @@ -96,22 +96,16 @@ final class IssuesViewController: UIViewController, ListAdapterDataSource, FeedD } func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController { - if object is NSAttributedStringSizing { - return IssueTitleSectionController() - } else if object is IssueCommentModel { - return IssueCommentSectionController(client: client) - } else if object is IssueLabelsModel { - return IssueLabelsSectionController() - } else if object is IssueStatusModel { - return IssueStatusSectionController() - } else if object is IssueLabeledModel { - return IssueLabeledSectionController() - } else if object is IssueClosedModel { - return IssueClosedSectionController() - } else if object is IssueMergedModel { - return IssueMergedSectionController() + switch object { + case is NSAttributedStringSizing: return IssueTitleSectionController() + case is IssueCommentModel: return IssueCommentSectionController(client: client) + case is IssueLabelsModel: return IssueLabelsSectionController() + case is IssueStatusModel: return IssueStatusSectionController() + case is IssueLabeledModel: return IssueLabeledSectionController() + case is IssueClosedModel: return IssueClosedSectionController() + case is IssueMergedModel: return IssueMergedSectionController() + default: fatalError("Unhandled object: \(object)") } - return ListSectionController() } func emptyView(for listAdapter: ListAdapter) -> UIView? { diff --git a/Classes/Notifications/NotificationsViewController.swift b/Classes/Notifications/NotificationsViewController.swift index cf7c5f3d..99d4fa6c 100644 --- a/Classes/Notifications/NotificationsViewController.swift +++ b/Classes/Notifications/NotificationsViewController.swift @@ -80,12 +80,10 @@ RepoNotificationsSectionControllerDelegate { } func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController { - if object is SegmentedControlModel { - let controller = SegmentedControlSectionController() - controller.delegate = self - return controller - } else { - return RepoNotificationsSectionController(client: client, delegate: self) + switch object { + case is SegmentedControlModel: return SegmentedControlSectionController(delegate: self) + case is NotificationViewModel: return RepoNotificationsSectionController(client: client, delegate: self) + default: fatalError("Unhandled object: \(object)") } } diff --git a/Classes/Section Controllers/SegmentedControl/SegmentedControlSectionController.swift b/Classes/Section Controllers/SegmentedControl/SegmentedControlSectionController.swift index 5e46d78a..56facc46 100644 --- a/Classes/Section Controllers/SegmentedControl/SegmentedControlSectionController.swift +++ b/Classes/Section Controllers/SegmentedControl/SegmentedControlSectionController.swift @@ -16,6 +16,10 @@ protocol SegmentedControlSectionControllerDelegate: class { final class SegmentedControlSectionController: ListGenericSectionController, SegmentedControlCellDelegate { weak var delegate: SegmentedControlSectionControllerDelegate? = nil + init(delegate: SegmentedControlSectionControllerDelegate?) { + self.delegate = delegate + super.init() + } override func sizeForItem(at index: Int) -> CGSize { guard let context = collectionContext else { fatalError("Collection context must be set") } diff --git a/Classes/Settings/SettingsViewController.swift b/Classes/Settings/SettingsViewController.swift index f27ae855..d303928b 100644 --- a/Classes/Settings/SettingsViewController.swift +++ b/Classes/Settings/SettingsViewController.swift @@ -90,16 +90,17 @@ final class SettingsViewController: UIViewController, ListAdapterDataSource, Git } func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController { - guard let object = object as? ListDiffable else { fatalError() } + guard let object = object as? ListDiffable else { fatalError("Object not diffable") } if object === addKey, let mgr = rootNavigationManager { return SettingsAddAccountSectionController(rootNavigationManager: mgr) } else if object === signoutKey { return SettingsSignoutSectionController(sessionManager: sessionManager) } else if object === reportKey { return SettingsReportSectionController() - } else { + } else if object is GithubSessionManager { return SettingsUsersSectionController() } + fatalError("Unhandled object: \(object)") } func emptyView(for listAdapter: ListAdapter) -> UIView? { return nil } diff --git a/Resources/Info.plist b/Resources/Info.plist index f182789f..76216104 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.0.0 CFBundleVersion - 154 + 160 LSApplicationQueriesSchemes org-appextension-feature-password-management