How to define methods and properties that are visible only within objective-c?

I am trying to write an objective-c structure, and I would like to have methods and properties visible only within the framework. I know that I can define them in the class extension inside the implementation file, but then they will not be available to other classes.

One of the ways that I was going to do is to define a category, for example MyClass + Internals, and make this title private. but create the header MyClass.h. I was wondering if there is a better way to do this. Also, I'm not sure if you can define properties in a category, I thought these were just methods. Thanks for any suggestions or feedback.

+4
source share
1 answer

Say you have a class named "Foo", then in "Foo_Framework.h", create:

@interface Foo() @property ....; - .... method .... @end 

Then make sure that “Foo_Framework.h” is imported before @implementation Foo . This will compile the Foo class with the advanced interface found in the specified header file. This header can then be used throughout your structure. Just do not make it available outside the box.

You are right that you cannot declare properties (which are synthesized) in a category. This was one of the main motives for creating class extensions, an example of which is given above.

+3
source

Source: https://habr.com/ru/post/1441925/


All Articles