Eureka: Swift 3 Migration: onCellUnHighlight vs. onCellHighlightChanged

Created on 8 Dec 2016  路  2Comments  路  Source: xmartlabs/Eureka

I am currently in the middle of Swift 3 migration, and I just ran into a problem with the fact that onCellUnHighlight is now gone.

In my code, I would previously react to the UnHighlight event of a TextRow to trigger an API call (to update that String on the server). However, it seems that only onCellHighlightChanged is available now, but I do not seem to understand how we can get the type of "change" (i.e. highlight or unhighlight).

Here is the code I previously used in Swift 2 with the Eureka Swift 2 branch:

TextRow(DEVICE_NAME_TAG) { row in
    row.title = "Name"
    row.value = device?.name
    row.placeholder = "Your Device's Name"
}.onCellUnHighlight({ cell, row in
    self.deviceNameFieldChanged(row.value ?? "")
}).onCellHighlight({ _, _ in })

Now, I know I can just check if the value changed before triggering the API call made by deviceNameFieldChanged() (which I do) but I wanted to know if there was a way to know which highlight event was triggered (basicly, reproduce the old behavior)?

Thanks

highlight - unhighlight swift 3.0

Most helpful comment

Hi @Laptopmini,
Every row has a new boolean property isHighlighted so you should implement onCellHighlightChanged and within the closure code check the row.isHighlighted value.

Therefore the right migration code is...

.onCellHighlightChanged{ cell, row [weak self] in
    if !row.isHighlighted {
      self?.deviceNameFieldChanged(row.value ?? "")
   }
}

Hope it helps.

All 2 comments

Hi @Laptopmini,
Every row has a new boolean property isHighlighted so you should implement onCellHighlightChanged and within the closure code check the row.isHighlighted value.

Therefore the right migration code is...

.onCellHighlightChanged{ cell, row [weak self] in
    if !row.isHighlighted {
      self?.deviceNameFieldChanged(row.value ?? "")
   }
}

Hope it helps.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings