Skip to content

Commit

Permalink
Use an Iterator to generate the list of Items
Browse files Browse the repository at this point in the history
  • Loading branch information
Abizern committed Sep 20, 2017
1 parent 2e09a6f commit b478f2c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions PartialTable/DataSource.swift
Expand Up @@ -15,20 +15,18 @@ 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))
}()


func getMoreItems() {
numberOfItems = min(numberOfItems + numberOfItemsToAdd, maximumNumberOfItems)
}


func numberOfSections(in tableView: UITableView) -> Int {
switch (numberOfItems < maximumNumberOfItems) {
case true:
Expand All @@ -38,7 +36,6 @@ class DataSource: NSObject, UITableViewDataSource {
}
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
Expand All @@ -50,7 +47,6 @@ class DataSource: NSObject, UITableViewDataSource {
}
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
Expand Down

0 comments on commit b478f2c

Please sign in to comment.