There is a swift project in which I have an objective-C file. I would like to call a Swift class function from Objective-C file
What is the best way to do this ? I have done it using NSNotification
but wanted to know if there is a better way to do this.
Test-Bridging-Header.h
#import "ObjectiveC.h"
ClassA.swift
@objc class ClassA {
func f1() {
}
}
ObjectiveC.h
void objC_f1()
ObjectiveC.m
void objC_f1() {
//Create an instance of ClassA and call function f1
}
Conclusion
- There was some trouble caused because I was had a testcase scheme.
- When I created a new project without a testcase scheme, it worked ok.
- Pls Note - The -Swift.h generated but will not be listed in the project navigator
- This answers my question - How to call Objective-C code from Swift