@class DataViewController;
is for
-(DataViewController *)viewControllerAtIndex:(NSUInteger)index
storyboard:(UIStoryboard *)storyboard;
@class is a forward declaration that tells the compiler to be a little forgiving to this method declaration that is meant to return a DataViewController object, and defer the handling to the implementation part.
You will eventually need #import "DataViewController.h" in ModelController.m.
Well... you could put #import "DataViewController.h" but... if DataViewController.h itself has an #import "ModelController.h" statement then the compiler will go in a circular import loop.
As for:
Why #import "DataViewController.h" in ModelController.m is not enough ?
- You're publicly declaring a method
-viewControllerAtIndex:storyboard: in ModelController.h.
- This tells classes importing
ModelController that it provides such a method.
- This method returns a
DataViewController object and since the possibility of DataViewController.h importing ModelController.h exists
- You need
@class DataViewController; in ModelController.h
- Since
@class is only a forward declaration, you need #import "DataViewController.h" in ModelController.m
If... the method is used within ModelController class only then you need not declare the method in the .h and thereby dropping the need for the @class DataViewController; statement.
Also, I like this generic answer on @class vs. #import