How a class extension works as a means of implementing private methods

≯℡__Kan透↙ 提交于 2019-12-06 06:25:06

That's not an "empty category", it's a class extension. Read Bbum's explanation of them at the link I provided.

That's because you create your empty category in your implementation file, not your header file so other classes can't 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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!