From b94898267440a492de2c629d4aed3c3457baef61 Mon Sep 17 00:00:00 2001 From: dirtmelon <0xffdirtmelon@gmail.com> Date: Mon, 12 Oct 2020 14:27:39 -0700 Subject: [PATCH] Replace if let with guard let (#1466) Summary: ## Changes in this pull request ### Checklist - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1466 Reviewed By: bdotdub Differential Revision: D24235336 Pulled By: lorixx fbshipit-source-id: bfc5fab26ae28ff9306d1b889b82b49c6ae2a636 --- Source/IGListSwiftKit/ListIdentifiable.swift | 10 ++++------ Source/IGListSwiftKit/ListValueSectionController.swift | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Source/IGListSwiftKit/ListIdentifiable.swift b/Source/IGListSwiftKit/ListIdentifiable.swift index 3a5d0489..8ec4f3d8 100644 --- a/Source/IGListSwiftKit/ListIdentifiable.swift +++ b/Source/IGListSwiftKit/ListIdentifiable.swift @@ -33,11 +33,10 @@ public extension ListIdentifiable { // TODO(natesm): Should this be a public API? It is for now. init?(diffable: Any) { - if let value = (diffable as? ListDiffableValueBox)?.value { - self = value - } else { + guard let value = (diffable as? ListDiffableValueBox)?.value else { return nil } + self = value } } @@ -63,10 +62,9 @@ private final class ListDiffableValueBox: NSObject, Lis } func isEqual(toDiffableObject object: ListDiffable?) -> Bool { - if let other = object as? ListDiffableValueBox { - return value == other.value - } else { + guard let other = object as? ListDiffableValueBox else { return false } + return value == other.value } } diff --git a/Source/IGListSwiftKit/ListValueSectionController.swift b/Source/IGListSwiftKit/ListValueSectionController.swift index e018c540..4b2b5d7a 100644 --- a/Source/IGListSwiftKit/ListValueSectionController.swift +++ b/Source/IGListSwiftKit/ListValueSectionController.swift @@ -23,12 +23,11 @@ open class ListValueSectionController: ListSectionContr /// Subclasses of `ListValueSectionController` may not override `didUpdate(to:)` for objects. /// Instead, they must use the overload for generic values. public final override func didUpdate(to object: Any) { - if let value = Value(diffable: object) { - self.value = value - didUpdate(to: value) - } else { + guard let value = Value(diffable: object) else { fatalError("Expected object for value section controller to be a boxed \(Value.self), but it was \(object)") } + self.value = value + didUpdate(to: value) } /// Updates the section controller to a new value.