What does this syntax mean relating to interface declaration?

余生颓废 提交于 2019-12-11 20:27:30

问题


This is from the ViewController.m file in a starter project from a tutorial for a game.

@interface ViewController()

//irrelevant stuff omitted

@end

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?


回答1:


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.)



来源:https://stackoverflow.com/questions/26940874/what-does-this-syntax-mean-relating-to-interface-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!