Here is my understanding:
Extensions are commonly used to add additional features to our own custom class . We can add private methods or properties that extend the class interface that can be used in the implementation of the class.
Extensions must be written in the same file as the class. Therefore, you cannot write extensions for predefined types such as String, Float, etc.
On the other hand, categories can be used to add additional methods to pre-existing classes. For example, we can create custom methods by extending the String class. Please note that it cannot create additional properties in categories. In addition, the main advantage of categories is that we can write categories in any other file, outside the file in which your class terminates.
When creating categories, you must include the name in parentheses. But the extension does not require a name. Therefore, several times they are also called anonymous categories.
iPhoneDeveloper Oct 08 '17 at 12:41 on 2017-10-08 12:41
source share