Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Fixed get chapter name method, applied recursive search for toc refer…
Browse files Browse the repository at this point in the history
…ence.
  • Loading branch information
wesleycgs committed Jun 29, 2018
1 parent b8cccd7 commit 4577d99
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Source/FolioReaderCenter.swift
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1000,19 +1000,25 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
Find and return the current chapter name.
*/
public func getCurrentChapterName() -> String? {
for item in self.book.flatTableOfContents {
guard
let reference = self.book.spine.spineReferences[safe: (self.currentPageNumber - 1)],
let resource = item.resource,
(resource == reference.resource),
let title = item.title else {
continue
var foundChapterName: String?

func search(_ items: [FRTocReference]) {
for item in items {
guard foundChapterName == nil else { break }

if let reference = self.book.spine.spineReferences[safe: (self.currentPageNumber - 1)],
let resource = item.resource,
resource == reference.resource,
let title = item.title {
foundChapterName = title
} else if let children = item.children, children.isEmpty == false {
search(children)
}
}

return title
}

return nil
search(self.book.flatTableOfContents)

return foundChapterName
}

// MARK: Public page methods
Expand Down

0 comments on commit 4577d99

Please sign in to comment.