Subclassification vs Expansion in Fast

I want to configure one UITextField for some reason. Therefore, I have currently subclassed it and added several methods.

Can I use the extension over UITextField instead? What is a good approach? Please explain!

+8
swift
source share
1 answer

As a general rule (YMMV):

  • Are you adding universal functions that should be available to all UITextField ? . If yes, do the extension. All instances of UITextField can call new methods.
  • Do you UITextField functionality that should be limited to special instances of UITextField that you define exactly? If so, create a subclass. Only instances of the subclass can use new methods.

There are other technical considerations, for example, extensions cannot add fields, for example.

+39
source share

All Articles