此语法与接口声明有关意味着什么? [英] What does this syntax mean relating to interface declaration?
问题描述
这是来自游戏教程的入门项目中的ViewController.m文件.
This is from the ViewController.m file in a starter project from a tutorial for a game.
@interface ViewController()
//irrelevant stuff omitted
@end
是让我感到困惑的是ViewController()
位.我了解公共接口和私有接口之间的区别,但是直到现在在Objective-C中我还没有使用私有接口.我曾经在公共界面上看到过这样的东西:
It's the ViewController()
bit that confuses me. I understand the different between public and private interfaces, but I haven't used a private interface til now in Objective-C. I'm used to seeing something like this instead, for the public interface:
@interface ViewController : UIViewController
那么为什么现在它只是第一个带有括号且没有继承符号的?
So why now is it just the first one, and with parentheses, with no inheritance notation?
推荐答案
That's a class extension. It allows for declaring additional interface, usually private because it's in an implementation (.m) file. It's similar to a category, except that the compiler will require you to supply the implementation for any interface declared within it. (A category can declare an interface even if nothing provides any implementation.)
这篇关于此语法与接口声明有关意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!