2

I need to call my AppDelegate function of Objective-C from the Swift class of the same project. The function definition is in Objective-C AppDelegate. I need to call from Swift class existing in the same project.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

2

Create a Bridging Header file and add

#import "AppDelegate.h"

Add your function definition in AppDelegate.m and function declaration

AppDelegate.m

- (NSString *)test {
    return @"test";
}

AppDelegate.h

- (NSString *)test;

In Swift file

if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
    print(appDelegate.test())
}
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70