Here, $.isStarted a boolean virtual property, but that all appears to be working correctly. I can breakpoint within the .sectionBy closure and it's running and returning the correct string, but 0 or 1 is still appearing as the section header of my list. Do I need to implement titleForHeader / viewForHeaderInSection? It says to do so under the ListMonitor documentation but not the list publisher documentation. If so, what would I access to see my transformed string?
Originally created by @joeljfischer on GitHub (Jan 1, 2021).
Hi, I have a `.sectionBy` clause set up, but it appears that the name transformer isn't working.
```swift
listPublisher = CoreStoreDefaults.dataStack.publishList(
From<Stopwatch>()
.sectionBy(\.$isStarted, { (sectionName) -> String? in
if sectionName == "1" {
return "Running".localized()
} else {
return "Stopped".localized()
}
})
.orderBy(.descending(\.$name))
)
```
Here, `$.isStarted` a boolean virtual property, but that all appears to be working correctly. I can breakpoint within the `.sectionBy` closure and it's running and returning the correct string, but `0` or `1` is still appearing as the section header of my list. Do I need to implement `titleForHeader` / `viewForHeaderInSection`? It says to do so under the `ListMonitor` documentation but not the list publisher documentation. If so, what would I access to see my transformed string?
@joeljfischer The titleForHeader / viewForHeaderInSection for DiffableDataSource adapters currently doesn't support the custom sectionIndex transformers, sorry about that. I'll try to rework the adapters in an update, but for now you have the following options to work around it:
Subclassing DiffableDataSource.TableViewAdapter or DiffableDataSource.CollectionViewAdapter and override the tableView(_:titleForHeaderInSection:) or collectionView(_:viewForSupplementaryElementOfKind:at:)
Adding a Field.Virtual property that implements the logic. You can then use that property as the sectionBy key. See the Demo app's example:
@Field.Virtual("colorGroup",customGetter:{object,fieldinifletcolorGroup=field.primitiveValue{returncolorGroup}letcolorGroup:Stringswitchobject.$hue.value*359{case0..<20:colorGroup="Lower Reds"case20..<57:colorGroup="Oranges and Browns"case57..<90:colorGroup="Yellow-Greens"case90..<159:colorGroup="Greens"case159..<197:colorGroup="Blue-Greens"case197..<241:colorGroup="Blues"case241..<297:colorGroup="Violets"case297..<331:colorGroup="Magentas"default:colorGroup="Upper Reds"}field.primitiveValue=colorGroupreturncolorGroup})varcolorGroup:String
@JohnEstropia commented on GitHub (Jan 3, 2021):
@joeljfischer The titleForHeader / viewForHeaderInSection for DiffableDataSource adapters currently doesn't support the custom sectionIndex transformers, sorry about that. I'll try to rework the adapters in an update, but for now you have the following options to work around it:
- Subclassing `DiffableDataSource.TableViewAdapter` or `DiffableDataSource.CollectionViewAdapter` and override the `tableView(_:titleForHeaderInSection:)` or `collectionView(_:viewForSupplementaryElementOfKind:at:)`
- Adding a `Field.Virtual` property that implements the logic. You can then use that property as the `sectionBy` key. See the Demo app's example:
```swift
Modern.ColorsDemo.dataStack.publishList(
From<Modern.ColorsDemo.Palette>()
.sectionBy(\.$colorGroup)
/ /...
)
```
```swift
@Field.Virtual(
"colorGroup",
customGetter: { object, field in
if let colorGroup = field.primitiveValue {
return colorGroup
}
let colorGroup: String
switch object.$hue.value * 359 {
case 0 ..< 20: colorGroup = "Lower Reds"
case 20 ..< 57: colorGroup = "Oranges and Browns"
case 57 ..< 90: colorGroup = "Yellow-Greens"
case 90 ..< 159: colorGroup = "Greens"
case 159 ..< 197: colorGroup = "Blue-Greens"
case 197 ..< 241: colorGroup = "Blues"
case 241 ..< 297: colorGroup = "Violets"
case 297 ..< 331: colorGroup = "Magentas"
default: colorGroup = "Upper Reds"
}
field.primitiveValue = colorGroup
return colorGroup
}
)
var colorGroup: String
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @joeljfischer on GitHub (Jan 1, 2021).
Hi, I have a
.sectionByclause set up, but it appears that the name transformer isn't working.Here,
$.isStarteda boolean virtual property, but that all appears to be working correctly. I can breakpoint within the.sectionByclosure and it's running and returning the correct string, but0or1is still appearing as the section header of my list. Do I need to implementtitleForHeader/viewForHeaderInSection? It says to do so under theListMonitordocumentation but not the list publisher documentation. If so, what would I access to see my transformed string?@JohnEstropia commented on GitHub (Jan 3, 2021):
@joeljfischer The titleForHeader / viewForHeaderInSection for DiffableDataSource adapters currently doesn't support the custom sectionIndex transformers, sorry about that. I'll try to rework the adapters in an update, but for now you have the following options to work around it:
DiffableDataSource.TableViewAdapterorDiffableDataSource.CollectionViewAdapterand override thetableView(_:titleForHeaderInSection:)orcollectionView(_:viewForSupplementaryElementOfKind:at:)Field.Virtualproperty that implements the logic. You can then use that property as thesectionBykey. See the Demo app's example: