I have tried to make a location autocomplete text view class by subclassing UITextField
and use Google Place Autocomplete API. This works great, but I have a design error due to the implementation. To observe when the user types text, I set the UITextFieldDelegate
to self
in the custom subclass and track changes to the typed text in textView:shouldChangeTextInRange:replacementText:
. This works, but here is the design error: If someone now wants to check what is typed into the custom subclass by setting the delegate to something new, the delegate of my class is not set to the object of the class itself anymore. Now the custom class is useless. Is there any way to either get the text as it is typed without the delegate, prevent the delegate from being changed, or in any other way fix my problem?
A few options I have though about that could work, but in a bad way:
- Check regularly what the
text
property is: Should be obvious why busy waiting is a stupid idea - Override the delegate property and set it to private: Not sure if this will even work, but if it did, the class is no longer a proper subclass of UITextField and all delegate methods are unavailable when implementing my subclass.
- Provide a new delegate for further use of the delegate: Allows someone to get the same things as the
UITextFieldDelegate
provides, but it still messes up the documentation and proper implementation ofUITextField