What is category and class extension? How these differ?



What is category and class extension? How these differ?..

Answer / Pramd Kumar

A category in Objective-C is a way of extending an existing class by adding new methods, properties, or categories (other categories). Categories are declared using the @category directive, which specifies the name of the category and the name of the original class that it extends. Categories can be used to add functionality to existing classes without modifying their source code.nnClass extensions in Swift are similar to categories in Objective-C, but they are a part of the source file for the class they extend. Class extensions allow you to add additional properties and methods that are not exposed to the public interface of the class. Unlike categories, class extensions do not affect the behavior of existing instances of the class.nnThe main difference between categories and class extensions is that categories can be used with any existing class, while class extensions must be defined within the source file for the class they extend.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Apple iOS Interview Questions

Define decoding or deserialization?

1 Answers  


What is difference between weak and strong in ios?

1 Answers  


Explain me how to parse json?

1 Answers  


What is category and extension in ios?

1 Answers  


What is auto-layout?

1 Answers  


What are the skills required for ios developer?

1 Answers  


What is difference between shallow copy and deep copy in ios ? : IOS Architect

1 Answers  


What does ns stand for ios?

1 Answers  


What is latest ios version?

0 Answers  


Explain what is a framework?

1 Answers  


 Are document objects required for an application? What does they offer?

1 Answers  


Difference between coredata & sqlite?

1 Answers  


Categories