Group Group Group Group Group Group Group Group Group

Focusable UI elements

Hello, first of all I want say thanks for great book!
As in one of chapters from book we can see that UIKit classes have focus updates.
I have UISegmentedControl, where I want get it’s focus state. So far I found that actually focus comes to UISegment, not UISegmentedControl. Through debugging I see we have list of segments and one of them has focused = YES.
Help me please figure out how I can access this UISegment.

Are you looking for selectedSegmentIndex?

No, I look for UISegmentedControl.isFocused which give me false.
I debugged through the UIScreen.main.focusedView where I got
Optional(<UISegment: 0x7fdc84f0ee90; frame = (0 0; 189 70); opaque = NO; focused = YES; layer = <CALayer: 0x61800003b740>>)
So how could I access this UISegment ?

if let currentFocus = UIScreen.main.focusedView {
        if let superView = currentFocus.superview {
            if superView.tag == 11 {
            } else {

This is my work around to get right view and get it’s focused state.

If it works you might not want to change it, but have you thought of overriding

func didUpdateFocus(in: UIFocusUpdateContext, with: UIFocusAnimationCoordinator)

in the view controller and trying to monitor the focused view there?