view raw
Mayank Jain Mayank Jain - 7 months ago 141
Swift Question

Swift 3- How to override a method in subclass

In Swift 3, I want to override caretRectForPosition method of

in its subclass say

Here is my code which is working fine prior to Swift 2.3

import UIKit

class CustomTextField: UITextField {
override func caretRectForPosition(position: UITextPosition) -> CGRect {

but in Swift 3 its showing a compile time error Method does not override any method from its superclass.

Can any one help me out on this.

I am using this code to hide the cursor of text field.

Thanks in advance.


In Swift 3 caretRectForPosition(position:) is changed to caretRect(for:).

override func caretRect(for position: UITextPosition) -> CGRect {

Check Apple Documentation for more detail on UITextInput.