Overriding UITextField delegate methods
<p>I'm converting this Objective-C project (<a href="https://github.com/TomSwift/TSCurrencyTextField" rel="nofollow">TSCurrencyTextField</a>) to Swift. It's a <code>UITextField</code> subclass formatted to accept currency values. <a href="https://github.com/TomSwift/TSCurrencyTextField/blob/master/TSCurrencyTextField/TSCurrencyTextField.m" rel="nofollow">This</a> is the <code>.m</code> file I'm trying to convert.</p>

<p>In it, the <code>UITextField</code>'s method <code>shouldChangeCharactersInRange</code> is overridden with a parameter of type <code>TSCurrencyTextField</code>. Like so (look at the very last method),</p>

<pre><code>@interface TSCurrencyTextFieldDelegate : NSObject &lt;UITextFieldDelegate&gt;
@property (weak, nonatomic) id&lt;UITextFieldDelegate&gt; delegate;
@end

@implementation TSCurrencyTextField
{
    TSCurrencyTextFieldDelegate* _currencyTextFieldDelegate;
}

- (id) initWithFrame: (CGRect) frame
{
    self = [super initWithFrame: frame];
    if ( self )
    {
        [self TSCurrencyTextField_commonInit];
    }
    return self;
}

- (void) TSCurrencyTextField_commonInit
{
    // ...

    _currencyTextFieldDelegate = [TSCurrencyTextFieldDelegate new];
    [super setDelegate: _currencyTextFieldDelegate];
}

- (void) setDelegate:(id&lt;UITextFieldDelegate&gt;)delegate
{
    _currencyTextFieldDelegate.delegate = delegate;
}

- (id&lt;UITextFieldDelegate&gt;) delegate
{
    return _currencyTextFieldDelegate.delegate;
}

@end


@implementation TSCurrencyTextFieldDelegate

- (BOOL) textField: (TSCurrencyTextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string
{
    // ...
}

@end
</code></pre>

<p>Here's my Swift transalation.</p>

<pre><code>protocol CurrencyTextFieldDelegate: NSObjectProtocol, UITextFieldDelegate {
    weak var delegate: UITextFieldDelegate? { get set }
}

public class CurrencyTextField: UITextField {

    override public var delegate: UITextFieldDelegate? {
        get {
            return self.delegate as? CurrencyTextFieldDelegate
        }
        set {
            self.delegate = newValue
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }

    private func commonInit() {

    }
}

// MARK: - CurrencyTextFieldDelegate
extension CurrencyTextField: CurrencyTextFieldDelegate {
    public func textField(textField: CurrencyTextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -&gt; Bool {
        return false
    }
}
</code></pre>

<p>But I get the following error.</p>

<blockquote>
  <p>Objective-C method
  'textField:shouldChangeCharactersInRange:replacementString:' provided
  by method
  'textField(<em>:shouldChangeCharactersInRange:replacementString:)'
  conflicts with optional requirement method
  'textField(</em>:shouldChangeCharactersInRange:replacementString:)' in
  protocol 'UITextFieldDelegate'</p>
</blockquote>

<p>How do I fix this error?</p>