新手提问,看别人的代码是这样写的:
@interface FirstViewController() -(void)timerOnActive; -(void)getDataFromCD; @end @implementation FirstViewController @synthesize userID; @synthesize timer;
上面的代码是写在.m文件里的,我的问题是为什么不把
@interface FirstViewController() -(void)timerOnActive; -(void)getDataFromCD; @end
写在.h文件的@interface中? FirstViewController() 后面的那个括号是空的,需要填什么吗?这样写是为了补充吗?
The @interface FirstViewController() here is actually a class extension, just like an anonymous category. The methods it declares must be implemented in the main @implementation code block of the corresponding class. A class may have a publicly declared API , while having additional methods declared as private for use only by the class or framework class. You can declare such a method using a category (or more than one category) in a private header file or implementation file mentioned above. This works, but the compiler cannot confirm that all declared methods are implemented.
The method written in the m file cannot be called by external classes. This method is treated as a private method and called within this class. It is hidden from the outside world.