sectionIndexTitles and sectionForSectionIndexTitle #26

Closed
opened 2025-12-29 18:21:36 +01:00 by adam · 4 comments
Owner

Originally created by @markkrenek on GitHub (Jan 5, 2016).

Originally assigned to: @JohnEstropia on GitHub.

How do we get access to NSFetchedResultsController's sectionIndexTitles and sectionForSectionIndexTitle when using a sectioned list?

Originally created by @markkrenek on GitHub (Jan 5, 2016). Originally assigned to: @JohnEstropia on GitHub. How do we get access to NSFetchedResultsController's sectionIndexTitles and sectionForSectionIndexTitle when using a sectioned list?
adam added the fixed label 2025-12-29 18:21:36 +01:00
adam closed this issue 2025-12-29 18:21:36 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jan 6, 2016):

@markkrenek There's currently no interface to expose these (yet). Let me push an update within the day.
If you need to, you can workaround with these:

Getting Section Index Titles:

let monitor = // ... ListMonitor
let sectionIndexTitles: [String] = (0 ..< monitor.numberOfSections())
    .map({ monitor.sectionInfoAtIndex($0) })
    .map({ $0.indexTitle ?? "" })
// Apple's documentation states:
// "The default implementation returns the array created by calling sectionIndexTitleForSectionName: on all the known sections."
// which is similar to what we're doing here

Getting Index for an Index Title:

let sectionIndexTitle = "Apple"
let sectionForSectionIndexTitle: Int? = (0 ..< monitor.numberOfSections())
    .lazy
    .map({ monitor.sectionInfoAtIndex($0) })
    .indexOf({ $0.indexTitle == sectionIndexTitle })
@JohnEstropia commented on GitHub (Jan 6, 2016): @markkrenek There's currently no interface to expose these (yet). Let me push an update within the day. If you need to, you can workaround with these: Getting Section Index Titles: ``` swift let monitor = // ... ListMonitor let sectionIndexTitles: [String] = (0 ..< monitor.numberOfSections()) .map({ monitor.sectionInfoAtIndex($0) }) .map({ $0.indexTitle ?? "" }) // Apple's documentation states: // "The default implementation returns the array created by calling sectionIndexTitleForSectionName: on all the known sections." // which is similar to what we're doing here ``` Getting Index for an Index Title: ``` swift let sectionIndexTitle = "Apple" let sectionForSectionIndexTitle: Int? = (0 ..< monitor.numberOfSections()) .lazy .map({ monitor.sectionInfoAtIndex($0) }) .indexOf({ $0.indexTitle == sectionIndexTitle }) ```
Author
Owner

@JohnEstropia commented on GitHub (Jan 6, 2016):

@markkrenek The workaround I posted a while ago is WRONG, sorry about that. I forgot that section indexes are independent of the sections themselves. Anyway you can access these methods from ListMonitor now:

public func sectionIndexTitles() -> [String]
public func targetSectionForSectionIndex(title title: String, index: Int) -> Int

See 71c3abc4f3 for details.

@JohnEstropia commented on GitHub (Jan 6, 2016): @markkrenek The workaround I posted a while ago is WRONG, sorry about that. I forgot that section indexes are independent of the sections themselves. Anyway you can access these methods from `ListMonitor` now: ``` swift public func sectionIndexTitles() -> [String] public func targetSectionForSectionIndex(title title: String, index: Int) -> Int ``` See https://github.com/JohnEstropia/CoreStore/commit/71c3abc4f31241e9ab95b639071cfeaacb253489 for details.
Author
Owner

@markkrenek commented on GitHub (Jan 6, 2016):

Works great. Thanks John. I've just started experimenting with this library, and so far it is great.

@markkrenek commented on GitHub (Jan 6, 2016): Works great. Thanks John. I've just started experimenting with this library, and so far it is great.
Author
Owner

@JohnEstropia commented on GitHub (Jan 6, 2016):

@markkrenek Glad it works :) Thanks for the feedback!

@JohnEstropia commented on GitHub (Jan 6, 2016): @markkrenek Glad it works :) Thanks for the feedback!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore-JohnEstropia#26