diff --git a/PartialTable/DataSource.swift b/PartialTable/DataSource.swift index 732a1d3..19bd26a 100644 --- a/PartialTable/DataSource.swift +++ b/PartialTable/DataSource.swift @@ -15,12 +15,11 @@ class DataSource: NSObject, UITableViewDataSource { private var numberOfItems = 10 lazy private var items: [Item] = { - var list = [Item]() - for _ in 0 ..< self.maximumNumberOfItems { - list.append(Item(value: UUID().uuidString)) + let iterator = AnyIterator { + return Item(value: UUID().uuidString) } - - return list + + return Array(iterator.prefix(maximumNumberOfItems)) }() @@ -28,7 +27,6 @@ class DataSource: NSObject, UITableViewDataSource { numberOfItems = min(numberOfItems + numberOfItemsToAdd, maximumNumberOfItems) } - func numberOfSections(in tableView: UITableView) -> Int { switch (numberOfItems < maximumNumberOfItems) { case true: @@ -38,7 +36,6 @@ class DataSource: NSObject, UITableViewDataSource { } } - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch section { case 0: @@ -50,7 +47,6 @@ class DataSource: NSObject, UITableViewDataSource { } } - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch indexPath.section { case 0: