问题
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