ios - @interface 和@implementation 指令中括号内的文本是什么意思?

标签 ios objective-c uiviewcontroller

我有一个关于 Apple 示例代码的非常基本的问题。在 .m 文件中,类声明如下所示:

@interface MyMovieViewController (OverlayView)
[...]
@end

@interface MyMovieViewController (ViewController)
[...]
@end

@implementation MyMovieViewController(ViewController)
[...]
@end

@implementation MyMovieViewController (OverlayView)
[...]
@end

@implementation MyMovieViewController
[...]
@end

完整代码 here .

括号内的内容(“OverlayView”和“ViewController”)似乎只是为了帮助分解代码并使其更具可读性,但实际上并不影响代码的执行。但我不想误解一些重要的事情,所以我想我会检查一下以确保。

我的理解对吗?谢谢!

最佳答案

这些称为类别,允许您向您的类添加更多功能。

A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing. Using categories, you can also distribute the implementation of your own classes among several files. Class extensions are similar, but allow additional required APIs to be declared for a class in locations other than within the primary class @interface block.

From the Apple docs on Categories and Extensions.

关于ios - @interface 和@implementation 指令中括号内的文本是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7378479/

相关文章:

ios - 上周 Itunes 连接变化

ios - 单击表格 View 单元格时隐藏 UIImageView

ios - 通过 View Controller 、标签栏 Controller 、导航 Controller 和 View Controller 传递数据

ios - 关闭 UIViewController 时重新加载 TableView?

iphone - MPMediaItem 到 AVAsset 到 .MP3

ios - 如何在 iOS 中使用 Cocos2d V3 制作类似 Candy Crush Saga 应用程序的 Ray Animation

iphone - 如何处理 iOS 4 以下 iPhone 中的电话中断

objective-c - [[NSMutableArray alloc] init] 和 [@[] mutableCopy] 有什么区别?

iphone - UIViewController 编辑按钮状态始终相同

ios - ViewController 模态演示未出现