Reputation: 51
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.
Upvotes: 2
Views: 365
Reputation: 15778
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())
}
Upvotes: 2