新手提问:Objective-C中在@implementation上加一个@interface的有什么不同?
伊谢尔伦
伊谢尔伦 2017-04-21 11:16:01
0
2
603

新手提问,看别人的代码是这样写的:

@interface FirstViewController() 
-(void)timerOnActive;
-(void)getDataFromCD;
@end

@implementation FirstViewController
@synthesize userID;
@synthesize timer;

上面的代码是写在.m文件里的,我的问题是为什么不把

@interface FirstViewController() 
-(void)timerOnActive;
-(void)getDataFromCD;
@end

写在.h文件的@interface中? FirstViewController() 后面的那个括号是空的,需要填什么吗?这样写是为了补充吗?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
Peter_Zhu

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template