# Unable to call swift extension method from Objective C class

**URL:** <https://forums.swift.org/t/unable-to-call-swift-extension-method-from-objective-c-class/67174>\
**Category:** Using Swift\
**Created:** [September 7, 2023, 5:59pm UTC](https://forums.swift.org/t/unable-to-call-swift-extension-method-from-objective-c-class/67174 "2023-09-07T17:59:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishdeshmukh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vishdeshmukh/32/21103_2.png) [@vishdeshmukh](https://forums.swift.org/u/vishdeshmukh)\
**Post date:** [September 7, 2023, 5:59pm UTC](https://forums.swift.org/t/unable-to-call-swift-extension-method-from-objective-c-class/67174/1 "2023-09-07T17:59:42Z")

</div>

I have created swift extension for the class ViewController and defined one method in it. When I try to call same that method from the same Obj-c ViewController, it gives me an error below:

`No visible @interface for 'ViewController' declares the selector 'testMe`

My Code is as below:

Objective-C class

```swift
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

[self testMe]; // No visible @interface for 'ViewController' declares the selector 'testMe'

}
@end

```

Swift extension:  
// ViewController+extnesion.swift

```swift
import UIKit

@objc public extension ViewController {
    
    func testMe() {
        print("Vish")
    }
}

```

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [September 7, 2023, 6:03pm UTC](https://forums.swift.org/t/unable-to-call-swift-extension-method-from-objective-c-class/67174/2 "2023-09-07T18:03:35Z")

</div>

Your `.m` file needs to import the compatibility header that the Swift compiler emits.

---

<div class="post-metadata">

**Author:** ![vishdeshmukh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vishdeshmukh/32/21103_2.png) [@vishdeshmukh](https://forums.swift.org/u/vishdeshmukh)\
**Post date:** [September 7, 2023, 6:14pm UTC](https://forums.swift.org/t/unable-to-call-swift-extension-method-from-objective-c-class/67174/3 "2023-09-07T18:14:22Z")

</div>

> [@ksluder](#):
>
> header

Ah yeah, thank you. Below import made it worked.

#import "ExtensionTest-Swift.h"
