@interface和@implementation指令中括号内的文字是什么意思? [英] What does the text inside parentheses in @interface and @implementation directives mean?

查看:102
本文介绍了@interface和@implementation指令中括号内的文字是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've got a very basic question about some sample code from Apple. In the .m file, the class declarations look like this:

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

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

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

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

@implementation MyMovieViewController
[...]
@end

完整代码此处

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

It seems like the stuff inside parentheses ("OverlayView" and "ViewController") are just there to help break up the code and make it more readable, but don't actually impact the execution of the code. But I don't want to be misunderstanding something important, so I thought I'd check to make sure.

我的理解是否正确?谢谢!

Is my understanding right? Thanks!

推荐答案

这些被称为 Categories 并允许您进一步添加您的类的功能。

Those are called Categories and allow you to add further functionality to your classes.


类别允许您将方法添加到现有类 - 甚至是您没有源的类。类别是一个强大的功能,允许您在不进行子类化的情况下扩展现有类的功能。使用类别,您还可以在多个文件中分发您自己的类的实现。类扩展类似,但允许在主类@interface块以外的位置为类声明其他必需的API。

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.

来自Apple类别和扩展程序的文档。

这篇关于@interface和@implementation指令中括号内的文字是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆