From 221c2fbd209b90072ce576d85df1e70ce0a6b341 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Fri, 14 Oct 2016 17:36:10 -0700 Subject: [PATCH] Makes objects function more swifty. Summary: - [x ] All tests pass. Demo project builds and runs. - [ ] I added tests, an experiment, or detailed why my change isn't tested. - [ x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/70 Reviewed By: nlutsenko Differential Revision: D4025610 Pulled By: rnystrom fbshipit-source-id: 927e93cec5719466dc152f82a235d5a70e53109d --- .../SectionControllers/HorizontalSectionController.swift | 7 ++----- .../ViewControllers/SearchViewController.swift | 9 ++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Example/IGListKitExamples/SectionControllers/HorizontalSectionController.swift b/Example/IGListKitExamples/SectionControllers/HorizontalSectionController.swift index f6b5d36..34be10f 100644 --- a/Example/IGListKitExamples/SectionControllers/HorizontalSectionController.swift +++ b/Example/IGListKitExamples/SectionControllers/HorizontalSectionController.swift @@ -50,11 +50,8 @@ class HorizontalSectionController: IGListSectionController, IGListSectionType, I //MARK: IGListAdapterDataSource func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] { - var numbers = [Int]() - for i in 0..<(number ?? 0) { - numbers.append(i) - } - return numbers as [IGListDiffable] + guard let number = number else { return [] } + return (0.. IGListSectionController { diff --git a/Example/IGListKitExamples/ViewControllers/SearchViewController.swift b/Example/IGListKitExamples/ViewControllers/SearchViewController.swift index 30ee97a..5d959e5 100644 --- a/Example/IGListKitExamples/ViewControllers/SearchViewController.swift +++ b/Example/IGListKitExamples/ViewControllers/SearchViewController.swift @@ -48,13 +48,8 @@ class SearchViewController: UIViewController, IGListAdapterDataSource, SearchSec //MARK: IGListAdapterDataSource func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] { - var items: [IGListDiffable] = [searchToken] - for word in words { - if filterString == "" || word.lowercased().contains(filterString.lowercased()) { - items.append(word as IGListDiffable) - } - } - return items + guard filterString != "" else { return [searchToken] + words.map { $0 as IGListDiffable } } + return [searchToken] + words.filter { $0.lowercased().contains(filterString.lowercased()) }.map { $0 as IGListDiffable } } func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {