Reputation: 2397
In Objective-C I can create categories to extend a class. I can also add properties to them as they are basically only methods. However I cannot bind them with @synthesize or any other way I know. Therefore whenever I try to use them the app would crash.
Is there any use of properties in categories or are they just possible because it would break the logic of the language to forbid them. Could you give me a scenario where defining a property in a category would make sense?
Upvotes: 0
Views: 700
Reputation: 11839
The main use of defining property in category is in creating class extension, with the help of category when we create class extension then there we can define property and synthesise them as well.This is the way to achieve hiding of property for public access.
You can check this for more information - http://www.techpaa.com/2012/04/adding-properties-to-categories-and.html
Upvotes: 1
Reputation: 7976
From The Objective-C Programming Language guide
A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing.
Since you want to
add properties to them as they are basically only methods
You can use the category to add methods to the class.
Upvotes: 0