How class extensions work as a means of implementing private methods

I believe that the popular way to declare "private methods" in Objective-C is to create an extension of your class and declare the methods you would like to make as private.

I would like to learn more about how class extension makes working methods confidential.

  • Update: I asked this question with the wrong category of empty categories. Now I changed it as an extension of the class
+2
source share
2 answers

This is not an "empty category", this is an extension. Read their description of Bbum at the link I provided.

+3
source

This is because you create your empty category in your implementation file, and not in the header file, so that other classes cannot access it.

//TestClass.h @interface TestClass : NSObject { } -(void)publicMethod; @end //TestClass.m @interface TestClass() -(void)privateMethod; @end @implementation TestClass -(void)publicMethod { NSLog (@"public"); } -(void)privateMethod { NSLog (@"private"); } @end 
+1
source

All Articles