I create a category to method swizzled UITextField
, it's name like UITextField+MaxLength
, I implement the +load
method to do swizzled, but I didn't import it in prefix header or other files, just import it in SomeViewController
.
I think the swizzled should only work in SomeViewController
, but why the swizzled method be invoke in every UITextField
even a UISearchBar
? and the +load
method be invoke when I run the app?
Edit
I think I need point out why I using swizzled, because of I want to using KVO to observe the text changed, so I swizzled the setText
and associate a property NSNumber
named displayLength
, so, If I do not use KVO, I can remove the swizzled part of this category and I can do cut substring to specific max length.