为什么我在我创建的这个UIViewController文件中的.h和.m文件中看到@interface两次。 .m 中的那个似乎像一个构造函数。 是吗?
.h 文件
@interface BlackTimer : UIViewController
@end
.m 文件
@interface ViewController ()
@end
通常在 .m 文件中放置私有方法的所有声明
像这样写"私人"(或类似的东西)这个词是一个很好的用法:
@interface ViewController (private)
-(void)myPrivateMethod;
@end
.
m 文件中的@interface称为类扩展。这是一个很好的链接来解释它。希望这有帮助。这是关于类扩展的 Apple 文档。
实现文件 (.m) 中的@interface ViewController ()
定义是匿名类别。它允许定义您的类实现的 ivar、属性和消息,而无需将它们暴露给导入公共接口 (.h) 的其他对象。