gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:59:23 25 4
gpt4 key购买 nike

我有一个关于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com