---
title: "What is a .h file in Objective-C?"
description: "A .h file is a header that declares classes, methods and constants for other files to import, while the matching .m file holds the implementation."
url: "https://bugsee.com/answers/objective-c/understanding-the-h-file-extension/"
---

# What is a .h file in Objective-C?

A `.h` header file declares a class's public interface, which other files import. The implementation lives in the matching `.m` file.

```objc
// Greeter.h: the public interface
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface Greeter : NSObject
@property (nonatomic, copy) NSString *name;
- (NSString *)greeting;
@end

NS_ASSUME_NONNULL_END
```

```objc
// Greeter.m: the implementation
#import "Greeter.h"

@implementation Greeter
- (NSString *)greeting {
    return [NSString stringWithFormat:@"Hello, %@", self.name];
}
@end
```

- `#import` includes a header once, unlike `#include`, which can include it repeatedly.
- Keep headers small: forward-declare classes with `@class` and import the full header only in the `.m` file.
- Anything you declare in a `.h` is visible to every file that imports it, so put private properties in a class extension inside the `.m`.
- In mixed projects, a bridging header (a `.h` file) is how Swift sees your Objective-C code.

## Related questions

- [How do you use Swift code in an Objective-C project?](https://bugsee.com/answers/objective-c/how-to-use-swift-in-objective-c/)
