Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
fixes another case of #4
Browse files Browse the repository at this point in the history
  • Loading branch information
icanzilb committed Nov 15, 2017
1 parent 61e2a16 commit e00a668
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions RealmContent/Core/View/ContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
// MARK: - private properties
private let tableView = UITableView()
public var page: ContentPage!
private var elements: Results<ContentElement>!
private var lastHashes = [Int]()

/// realm notifications
Expand Down Expand Up @@ -95,7 +96,7 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
populateFrom(page: page)

// enable updates
pageUpdatesToken = page.observe() { [weak self] change in
pageUpdatesToken = page.observe { [weak self] change in
switch change {
case .change(let properties):
for p in properties {
Expand All @@ -110,9 +111,8 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
}
}

pageElementsUpdatesToken = page.elements
.filter(NSPredicate(format: "type in %@", ContentElement.Kind.allRawValues()))
.observe(applyChanges)
elements = page.elements.filter(NSPredicate(format: "type in %@", ContentElement.Kind.allRawValues()))
pageElementsUpdatesToken = elements.observe(applyChanges)
}

private func populateFrom(page: ContentPage) {
Expand Down Expand Up @@ -179,7 +179,7 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return page.elements.count
return elements.count
}

internal var relayout: DispatchWorkItem?
Expand All @@ -196,7 +196,7 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let element = page.elements[indexPath.row]
let element = elements[indexPath.row]

guard let kind = ContentElement.Kind(rawValue: element.type) else {
return UITableViewCell()
Expand All @@ -222,7 +222,7 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
}

public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
customizeCell?(cell, indexPath, page.elements[indexPath.row])
customizeCell?(cell, indexPath, elements[indexPath.row])
}
}

Expand Down

0 comments on commit e00a668

Please sign in to comment.