Search code examples
uiviewswift3tvos

canBecomeFocused on swift 3


I'm trying to create a custom View which I need to focus. According to numerous Sources this is the way to go :

override func canBecomeFocused() -> Bool {
    return true
}

However after converting to Swift 3.0 this no longer works. It throws the error:

Method does not override any method from its superclass.

If i remove the override another error gets thrown:

Method 'canbecomeFocused()' with Objective-C selector 'canBecomeFocused' conflicts with better for 'canBecomeFocused' from superclass 'UIView' with the same Objective-C Selector.

Anyway I can make a UIView Selectable for TvOS?


Solution

  • In Swift 3 it is change to Instance Property, so try like this.

    override var canBecomeFocused: Bool {
        return true
    }
    

    Check Apple Documentation on canBecomeFocused for more details.