Why can I refer to UIKit classes after removing the import of UIKit.h?

cocoa-touch, header-files, import, objective-c

Solution

`UIKit.h` is just the file where the classes etc. are defined.

Without it, the compiler wouldn't know what `UIAlertView` is.

However, in your case it probably works anyway, as the `#import <UIKit/UIKit.h>` is usually included in your project's prefix file, which is included by default in your sources.

Problem

I've been watching a video that stated that `UIAlertView` works only if UIKit.h has been imported. However, if I comment out the import statement in the header file: ``` //#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end ``` the alert still works when I add it to the implementation file: ``` - (void)viewDidLoad { [super viewDidLoad]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; } ``` Please explain why this works? What is the true role of UIKit?

Original source